Description
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
.NET 6.0.100
Description
I have the following basic project definition:
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>21.0</SupportedOSPlatformVersion>
I then build and deploy a Release
version without explicitly specifying any related properties.
The app starts, but at some later point when using the app, some stuff is missing which then leads to the app crashing.
That is not completely unexpected, since the default behavior in .NET 6 is to aggressively link away pretty much everything that wasn't statically detected as being used.
I then set the following property:
<PublishTrimmed>false</PublishTrimmed>
The app builds, deploys and now also runs fully as expected.
Great, I could have stopped here, but didn't.
I then explicitly set the following property:
<AndroidLinkTool>r8</AndroidLinkTool>
When I now build the app, I get the following warning:
obj\Release\net6.0-android\android-x64\proguard\proguard_project_references.cfg: Warning XA4304 : ProGuard configuration file 'obj\Release\net6.0-android\android-x64\proguard\proguard_project_references.cfg' was not found.
When I run the app, I get the following exception immediately:
java.lang.ClassNotFoundException
2022-01-05 21:23:21.071 14245-14245/? E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/base.apk", zip file "/data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.arm64_v8a.apk", zip file "/data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.en.apk", zip file "/data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.xhdpi.apk"],nativeLibraryDirectories=[/data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/lib/arm64, /data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/base.apk!/lib/arm64-v8a, /data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.en.apk!/lib/arm64-v8a, /data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.xhdpi.apk!/lib/arm64-v8a, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:740)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:819)
at android.app.LoadedApk.getResources(LoadedApk.java:1041)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2360)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5996)
at android.app.ActivityThread.access$1200(ActivityThread.java:213)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.arm64_v8a.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:736)
... 12 more
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.mycompany.myapp-8tGi8cO_TcaLu_Bsb0_Pvw==/split_config.en.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
It appears, that suddenly R8 has trimmed so aggressively, that even the most basic stuff is missing.
I then disable trimming:
<AndroidLinkTool>r8</AndroidLinkTool>
<PublishTrimmed>false</PublishTrimmed>
The same exception is still being thrown.
I then try the following combination:
<AndroidLinkTool>r8</AndroidLinkTool>
<AndroidLinkMode>None</AndroidLinkMode>
The same exception is still being thrown.
I then disable shrinking via a Proguard configuration option:
<AndroidLinkTool>r8</AndroidLinkTool>
<PublishTrimmed>false</PublishTrimmed>
<ItemGroup>
<ProguardConfiguration Include="Proguard\**\*.cfg" />
</ItemGroup>
Proguard\KeepClasses.cfg:
-dontshrink
While the build warning is still being shown, the app now runs fine again.
So it appears that when I explicitly set <AndroidLinkTool>r8</AndroidLinkTool>
the behavior is different in comparison to when it is implicitly being set. This might be related to the proguard_project_references.cfg
file missing at build time.
The behavior should be the same in both cases (the one with the missing proguard_project_references.cfg
seems to be a bug).
Steps to Reproduce
See description.
Did you find any workaround?
Don't explicitly specify <AndroidLinkTool>r8</AndroidLinkTool>
.
Relevant log output
See description.