After build error Failed resolution of: Landroidx/work/R$bool;

Hello!
I’m trying update ironsource extention,

Here is my fork
IronSource, Facebook ads and Unity Ads works fine, but when i build with

// Add AdMob and Ad Manager Network
implementation 'com.google.android.gms:play-services-ads:20.2.0'
implementation 'com.ironsource.adapters:admobadapter:4.3.21'

i got error

log

2021-07-27 12:46:40.676 7311-7311/com.defironsource.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.defironsource.test, PID: 7311
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/work/R$bool;
at androidx.work.impl.WorkManagerImpl.(WorkManagerImpl.java:204)
at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:180)
at androidx.work.WorkManager.initialize(WorkManager.java:203)
at androidx.work.impl.WorkManagerInitializer.onCreate(WorkManagerInitializer.java:40)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2117)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2091)
at android.app.ActivityThread.installProvider(ActivityThread.java:7187)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6670)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6565)
at android.app.ActivityThread.access$1400(ActivityThread.java:224)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7560)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “androidx.work.R$bool” on path: DexPathList[[zip file “/data/app/com.defironsource.test-YeIAURzGGeg5CHIV4dNtrw==/base.apk”],nativeLibraryDirectories=[/data/app/com.defironsource.test-YeIAURzGGeg5CHIV4dNtrw==/lib/arm64, /data/app/com.defironsource.test-YeIAURzGGeg5CHIV4dNtrw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at androidx.work.impl.WorkManagerImpl.(WorkManagerImpl.java:204)
at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:180)
at androidx.work.WorkManager.initialize(WorkManager.java:203)
at androidx.work.impl.WorkManagerInitializer.onCreate(WorkManagerInitializer.java:40)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2117)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2091)
at android.app.ActivityThread.installProvider(ActivityThread.java:7187)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6670)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6565)
at android.app.ActivityThread.access$1400(ActivityThread.java:224)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7560)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Tryed build native java project in android studio, everythink works fine

solved with ext.manifest and aaptExtraPackages

1 Like

Nice! Happy to see that you managed to solve this!

1 Like

Thanks, have same problem.
aaptExtraPackages fixed it

2 Likes

I have a similar problem.

FATAL EXCEPTION: main
Process: com.albertgamesstudio.cbb, PID: 8156
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/startup/R$string;
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:183)
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:42)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1761)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1736)
at android.app.ActivityThread.installProvider(ActivityThread.java:6424)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6016)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5955)
at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1707)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6780)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1500)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1390)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “androidx.startup.R$string” on path: DexPathList[[zip file “/data/app/com.albertgamesstudio.cbb-1/base.apk”],nativeLibraryDirectories=[/data/app/com.albertgamesstudio.cbb-1/lib/arm64, /data/app/com.albertgamesstudio.cbb-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

May I ask what you (@S_R, @d954mas) typed in the aaptExtraPackages key?

1 Like
1 Like

Thanks @d954mas!

Typing the correct values ​​for aaptExtraPackages also fixed the errors for me. However, I have been investigating for a while why this should be done. I specified the required dependency in the build.gradle file, so in principle everything should be given in order for the project to build without error.

This is what the build.gradle file looks like:

dependencies {
implementation ‘com.google.android.gms:play-services-ads:20.5.0’
}

I had to add the following values ​​to aaptExtraPackages (in the app.appmanifest file) to run the app without error:

aaptExtraPackages: [“androidx.startup”, “androidx.work”, “com.google.android.gms.common”]

I was able to guess these values ​​by running the app and watching the logcat output for errors. In my previous post e.g. the first error was:

Caused by: java.lang.ClassNotFoundException: Did not find the class “androidx.startup.R $ string” on …

Accordingly, I was the first to add the string “androidx.startup” to aaptExtraPackages. Then running the app again came up with the following error which indicated the lack of the “androidx.work.R” class. So I also added the string “androidx.work” to aaptExtraPackages. I continued this method until the app ran error-free.

What the errors had in common was that the R class was missing in all cases. Looking into the app (with jadx) it seemed that until I added anything to aaptExtraPackages, a single R class was included in the entire project under my own package (com.albertgamesstudio.cbb). This R class contains all resource ids for all packages (e.g. androidx.startup, etc.). However, if I entered the appropriate values ​​for aaptExtraPackages, the same R class was built under each of the packages listed. This is obviously a redundancy here, as resource IDs for different packages are built multiple times everywhere.

So the reason for the problem is that the resource identifiers (which are in the R class) for different packages of dependencies are placed in a common R class. This R class is built under its my own package (com.albertgamesstudio.cbb). This way, when the app is running and a class in a dependency package refers to its own R class, it will not find it within its own package.

This structure is available in a file called “resource_ids.txt” inside the “project\build” directory. In this I see that all resource IDs are included under their own package (com.albertgamesstudio.cbb). An excerpt from the file:

com.albertgamesstudio.cbb:string/androidx_startup = 0x7f090000
com.albertgamesstudio.cbb:layout/notification_template_part_time = 0x7f080008
com.albertgamesstudio.cbb:layout/notification_template_icon_group = 0x7f080006
com.albertgamesstudio.cbb:layout/custom_dialog = 0x7f080002
com.albertgamesstudio.cbb:layout/browser_actions_context_menu_page = 0x7f080000
com.albertgamesstudio.cbb:id/wide = 0x7f060064
com.albertgamesstudio.cbb:styleable/SignInButton = 0x7f0b000a
com.albertgamesstudio.cbb:integer/google_play_services_version = 0x7f070000
com.albertgamesstudio.cbb:id/top = 0x7f060063
com.albertgamesstudio.cbb:string/common_google_play_services_install_button = 0x7f090004
com.albertgamesstudio.cbb:id/title = 0x7f060062

Due to the above, e.g. the first line would look something like this:

androidx.startup:string/androidx_startup = 0x7f090000

I made a test project in android studio to which I added my extension for the defold game. After that, I built an apk from it and looked inside. In addition to the packages for each dependency, android studio has added its own R class with the appropriate (only those that belong to it) resource IDs. In his opinion, this is the optimal structure.

I don’t know how understandable this is, what are your views @britzl and @Mathias_Westerdahl ? If necessary, I can also illustrate the problem with pictures.

It would be great if the defold builder could also solve this by generating multiple R classes, each for its own package. This way, you wouldn’t have to type anything for aaptExtraPackages, especially not guess what.

Sorry for not replying to this when you posted @coderm4ster ! We do have a task that we should be getting to fairly soon:

1 Like

That’s it! Thanks britzl!

This will certainly solve the need to generate multiple R.java files and package them for the appropriate packages.

1 Like