Some classes are not including in my APK

I am creating an Component and using many libraries. I used @UsesLibraries correctly. And Classes from JARs are including in APK but not all. I mean that there are few classes which are not including in my APK. Even after adding them in mainDexList.txt. Some experienced users of AI said that "Probably, classes are unused". Yes, It's unused. But I had use many JARs where it includes all used/unused classes in APK. Even without importing or mentioning them in mainDexList.txt. I have never faced this issue before.


Is there any way to force compiler to include all classes in APK from my JARs ?

Probably, an issue with multidexing. Since you are importing many JAR libraries, it is better to generate a new dex file in the Compiler.

1 Like

Typically you only need classes in mainClassDex file that are needed to start Screen1, and it's really only necessary on earlier versions of Android because Screen1 will attempt to load all of the additional dex files (called multidexing). Android versions 5+ perform ahead of time compilation and convert the dex files into oat files during installation. Do the libraries in question use proguard, or are you using proguard in your compilation?

I decompiled the APK and some classes are missing. How it can convert dex files into oat if there is no classes. Is proguard stopping them to include in APK ?

BTW, Sir @ewpatton, I have many classes having same name but exist in different path.
For Example -
com/appinventor/newbiedeveloper.class , com/appinventor/compponents/newbiedeveloper.class

these classes are not including in my APK.

But there are also some classes which is also in the same JAR and directory but it included in APK because these classes have different names. For Example -

com/appinventor/newbiedeveloper.class , com/appinventor/compponents/SirEwpatton.class

I think this is the problem with me sir @ewpatton
Still my question is same


Is there any way to force compiler to include all classes in APK from my JARs ?

I can't answer your questions without a better understanding what exactly you're trying to do, so let's get back to basics.

Are you doing this for an extension, or are you adding a custom component to your own version of App Inventor?

If you're doing this in your own version of App Inventor, have you included all of the necessary jars in build.xml?

Are you considering all of the classes.dex files? If the app has many classes, it will be automatically split up into a number of additional dex files.

Are the classes you are concerned about on the critical path for app startup? As I mentioned in my earlier comment only those needed to get Screen1 to the point where multidex can run are necessary to be in the classes.dex, everything else can go into classes2.dex, etc.

What is the symptom of these classes not appearing in the main dex file?

1 Like

My APK crashes while opening my app which is on Screen1. I had run some code in my component's constructor which is causing this error - NoClassFound. I added all neccasary libraries. I am working on my own version of Appinventor.

I send you libraries and java files. Can you run it on your localhost ?

Components aren't initialized until after the multidex process happens, unless you've changed something in the logic of the Form class.

I didn't make any changes in Form class.

If its not initialized then, Why it includes some classes from that JAR only

sir @ewpatton, I will be happy if you can run my component on your localhost. There is nothing related virus. It will not harm your PC