fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.02k stars 1.39k forks source link

Cannot set Android icon when using custom Manifest #3077

Open frei-0xff opened 2 years ago

frei-0xff commented 2 years ago

Describe the bug:

Android application build by fyne package -os android -release installs with default green android icon and not the one set in FyneApp.toml After inspecting apk file I found out that icon's PNG is properly added to /res/mipmap-xxxhdpi-v4/icon.png, but decoded AndroidManifest.xml looks like that:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="18" android:versionName="3.1.0" package="io.github.jacalz.test" platformBuildVersionCode="15" platformBuildVersionName="4.0.4-1406430">
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="30"/>
    <application android:label="FyneTest" android:icon="0x7f020000" android:debuggable="false">
        <activity android:theme="@style/Theme" android:label="FyneTest" android:name="org.golang.app.GoNativeActivity" android:configChanges="keyboardHidden|orientation|uiMode">
            <meta-data android:name="android.app.lib_name" android:value="FyneTest"/>
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

android:icon="0x7f020000" does not seem right.

To Reproduce:

Steps to reproduce the behaviour:

  1. Package any HelloWorld app by fyne package -os android -release
  2. Install apk on Android phone

Screenshots:

Example code:

Device (please complete the following information):

andydotxyz commented 2 years ago

Hmm, this has been working for years, I wonder what has happened. Can you please help by checking if using the “-icon” parameter has the same result?

frei-0xff commented 2 years ago

@andydotxyz Checked. Yes, it is the same with -icon parameter.

andydotxyz commented 2 years ago

Can you share the icon you are using? Is it certainly a PNG?

frei-0xff commented 2 years ago

@andydotxyz Yes, of course it is. Here it is: Icon Tried with standard Fyne's icon with gray cogwheel with the same result. I don't think it can depend on icon itself. As I already pointed out, the problem is in android:icon attribute in AndroidManifest.xml. It has to be something like @mipmap/icon.png but it is set to 0x7f020000. Edit: As I'm looking into fyne's source, I see that it is set to value 0x7f020000 on purpose. I'm just not competent enough to understand how it is supposed to work and why it doesn't. Edit2: Maybe the problem in resources.arsc file instead. I failed to decode it. Decoder returns error:

Error decode arsc
java.io.IOException: Expected entry start, expected offset: 0x258, actual: 0x268
    at jadx.core.xmlgen.ParserStream.checkPos(ParserStream.java:124)
    at jadx.core.xmlgen.ResTableParser.parseTypeChunk(ResTableParser.java:213)
    at jadx.core.xmlgen.ResTableParser.parsePackage(ResTableParser.java:169)
    at jadx.core.xmlgen.ResTableParser.decodeTableChunk(ResTableParser.java:118)
    at jadx.core.xmlgen.ResTableParser.decode(ResTableParser.java:66)
    at jadx.core.xmlgen.ResTableParser.decodeFiles(ResTableParser.java:71)
infamous40 commented 2 years ago

Hmm, this has been working for years, I wonder what has happened. Can you please help by checking if using the “-icon” parameter has the same result?

andydotxyz commented 2 years ago

Hmm, I cannot replicate this at all. Can you please try packaging one of our provided apps and see if it installs as expected on your device?

andydotxyz commented 2 years ago

Also what is the result printed for fyne version?

frei-0xff commented 2 years ago

@andydotxyz fyne cmd is the latest fyne cli version: v2.2.1 Is there any already packaged apk file that is known to show the right icon, so I can check it on my phone? Maybe the problem is in old Android version on my device or something like that.

andydotxyz commented 2 years ago

You could download one of the Fyne apps from the store? https://apps.fyne.io/playstore.html If you need to test a file directly best join one of our chat channels and someone can PM you one.

frei-0xff commented 2 years ago

@andydotxyz Tried to install Calculator and FyneGameBoy. They both installed with the default green icon. And won't run at all. Thus, it is an incompatibility problem, probably because of old Android version 5.1.1 on my device.

andydotxyz commented 2 years ago

Thanks for this. It should work on 5.1.1 though, I tested on 4.1. Is there anything helpful in the log when they crash and/or load perhaps relating to icon or otherwise.

frei-0xff commented 2 years ago

@andydotxyz How can I see the log on Android phone?

andydotxyz commented 2 years ago

Use adb logcat

frei-0xff commented 2 years ago

@andydotxyz Sorry, I don't have Android SDK installed. I used fyne-cross containers for packaging apk.

andydotxyz commented 2 years ago

I used fyne-cross containers for packaging apk.

Ah, this is crucial information. The fyne version of your system is not relevant like I had thought. What version of fyne-cross are you using?

frei-0xff commented 2 years ago

@andydotxyz I understand that. As I said, I use the latest version for packaging. I use cross-fyne's container fyneio/fyne-cross:1.2-android as environment for packaging. And before packaging I update fyne command to the latest version by go install fyne.io/fyne/v2/cmd/fyne@latest

andydotxyz commented 2 years ago

I use cross-fyne's container fyneio/fyne-cross:1.2-android as environment for packaging

You are not using the fyne-cross command itself?

And before packaging I update fyne command to the latest version by go install fyne.io/fyne/v2/cmd/fyne@latest

Indeed, but this will not be used by fyne-cross, as it is bundled into the container images.

frei-0xff commented 2 years ago

You are not using the fyne-cross command itself?

No, I'm running command fyne package -os android -release inside Docker container fyneio/fyne-cross:1.2-android that has preinstalled environment for building Android application. It's just easier than installing all of that on my local computer.

andydotxyz commented 2 years ago

Hmm, thanks.

Is this a standard Android device? What make/model is the 5.1.1 OS running on?

frei-0xff commented 2 years ago

Is this a standard Android device? What make/model is the 5.1.1 OS running on?

Yes, it's Huawei GR5. It is quite old.

snonux commented 9 months ago

I am having the same issue. However, the App is falling back to the default icon only when I have an AndroidManifest.xml and then run fyne package --os android --icon icon.png. Without any AndroidManifest.xml the icon just show sup correctly (but then I can't use the AndroidManifest.xml to request/set app storage permissions).

When I try to manually set the icon in the AndroidManifest.xml I get: "manual declaration of android:icon in AndroidManifest.xml not supported"

My manifest currently looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="org.buetow.quicklogger">

   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

   <application
       android:allowBackup="true"
       android:label="quicklogger"
       android:icon="icon">

        <activity android:name="org.golang.app.GoNativeActivity">
            <meta-data android:name="android.app.lib_name" android:value="npc" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
   </application>
</manifest>

I am using:

fyne version v2.4.3
andydotxyz commented 9 months ago

I am having the same issue. However, the App is falling back to the default icon only when I have an AndroidManifest.xml and then run fyne package --os android --icon icon.png. Without any AndroidManifest.xml the icon just show sup correctly (but then I can't use the AndroidManifest.xml to request/set app storage permissions).

When I try to manually set the icon in the AndroidManifest.xml I get: "manual declaration of android:icon in AndroidManifest.xml not supported"

My manifest currently looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="org.buetow.quicklogger">

   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

   <application
       android:allowBackup="true"
       android:label="quicklogger"
       android:icon="icon">

        <activity android:name="org.golang.app.GoNativeActivity">
            <meta-data android:name="android.app.lib_name" android:value="npc" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
   </application>
</manifest>

I am using:

fyne version v2.4.3

The icon reference will have to match the lookup generated in the compiled assets. I recommend generating an app without a custom manifest, then extracting it and making the changes you want, then running again. It should work.

snonux commented 9 months ago

Thanks, but that didn't work for me. When I extract the AndroidManifest.xml from the apk file and use that one I get still "manual declaration of android:icon in AndroidManifest.xml not supported".

What worked however (app icon showing up) was to clone the fyne project, change the occurances of android.permission.INTERNET to android.permission.MANAGE_EXTERNAL_STORAGE (as these are all the changes I want in my custom android manifest) in the source tree, re-compile fyne. Now all works. I know, this is more of an hammer approach!

andydotxyz commented 9 months ago

Updated the title to report the real issue. I think the solution may be to support generically adding permission /role requests in the app metadata which we can add to the platform specific formats when packaging.

snonux commented 9 months ago

Generic support for adding permissions in the app metadata would be good, indeed