I have more than 64k methods in my app.
When I hit the "Run" button and a pre Lollipop device connect4d, I get the 64k method error.
When I hit the "Run" button and a Lollipop or higher version device connected the apk is created.
What happens when I install this apk on a pre Lollipop device? it runs ok but is it risky?
I have more than 64k methods in my app.
If your app has more than 64k methods and you want to run it in pre-Lollipop devices then you have to enable Multidex. Otherwise, what will happen is that your code will be compiled into several DEX files (e.g. classes.dex, classes2.dex, classes3.dex, etc) but the pre-Lollipop device will only load the first DEX file and ignore classes in the secondary DEX files.
What happens when i install this apk on a pre lollipop device?
The installation will succeed. You might see warning messages about "classes failing to validate" in logcat but the installation will still be successful.
it runs ok but is it risky?
It will not run ok. The application might start and even run for a while but as soon as the system tries to load a class that was packed in one of the secondary DEX files, the app will crash with a ClassNotFoundException
. This might happen right away if the Activity
or Service
that you're trying to open uses one of said classes, but might also happen later when you exercise some code path that requires one of them.
Either way, the best solution is to use ProGuard or a similar tool to eliminate unused code and bring your app below the 64k method limit. If that doesn't work, the only other option is follow the instructions and recommendations in the official guide to continue to support pre-Lollipop devices.