I'm having an issue suddenly with the export process in Eclipse for licensing my Android app prior to release.
When I build normally under debug mode and deploy to the device, the file size is 11,782Mb. When I use the export process, the file is smaller, 11,322Mb. The file is corrupt and won't load when I test it on the device. When this process is successful, the file is the same size.
This happened once or twice before, and usually cleaning and rebuilding the project sorted it out, but now it's happening every time no matter what I do. Any ideas what is happening here please?
Edit: Production key is fine, use it all the time.
When I attempt to install the app, I get ClassNotFoundException:
java.lang.RuntimeException: Unable to instantiate application com.myapp.android.App: java.lang.ClassNotFoundException: Didn't find class "com.myapp.android.App" on path: DexPathList[[zip file "/data/app/com.myapp.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.myapp.app-1, /vendor/lib, /system/lib]]
There are several possible reasons for ClassNotFoundException that I have run into. Here are a few suggestions:
You mentioned "clean and rebuild" - for some reason (usually related to compiling the R.java file) I occasionally need to "clean" more than once for a good production build. I can even do a "clean" and export on a test that is fine, then do an export with a fail. I've probably done over 1000 deployments to Google Play across 50+ apps. It happens...
Android's Installer is corrupt. Yes - this happens, too. Sometimes with a production deployment (not with "debug" or "AVD" - but with "ADB" install or production installs) the Android installer will not ever install your app again. Factory reset of the device is the only solution. I believe an Android OS update can solve the problem, but I've only seen that work intermittently and haven't really tested it.
Manifest errors. Sometimes the production manifest file doesn't match the app classes. Usually this happens with a refactoring of class names. Eclipse in particular does not seem to always modify the manifest file properly. You may need to check it manually.
A res file changed. Sometimes when editing an XML document you will have an error that is not picked up by the compiler or IDE. You do a build and deploy to a test device that for some reason doesn't seem to use the resource or some other strange error. Usually it won't deploy anywhere properly, but I've seen it deploy to a test device and then not deploy in production. As a practice, I avoid this problem by occasionally "uninstalling" and then re-installing the app during testing.
The OP reminded me of another along the lines of the comment below (for future readers) - try deleting the generated files from the build. For example, anything in "BIN" and "GEN" can be deleted and re-built using "build." These files sometimes contain artifacts from previous builds that are no longer valid but are not detected during an automatic build process.
Those are some suggestions. Give them a try...
Related
I've encountered this error the second time today. For a while I'm able to build an APK (then I switch to dektop kit, then I switch back), and now I'm unable to build with this error:
Android deploy settings file not found, not building an APK.
first time I solved this by deleting the projectroot/android directory, deleting .user file and recreating those.
eventually it got broken again
now I switched from 5.14.1 to 5.12.7, it solved the issue, maybe temporarily, we'll see...
so my question is what that error message means, which file is the deploy settings file, which process puts it there, and which process deletes it and why?
Thank you for your answers in advance.
Restarting Qt Creator solved this issue for me
I know how to enable MultiDex support, but my problem is the opposite.
Seems like my Android Studio's MultiDex option is enabled by default for some reason.
When I unziped the resulting APK file and checked inside, there were two files.
classes.dex and classes2.dex.
You may say my project may hit 64K limit, but no, it doesn't.
I also tried without any dependencies and with some other gradle settings,
but the result was all the same.
I even put the line multiDexEnabled false, but it didn't help either.
So this time I created another new empty project, and hit the Run button without any modification.
Result? Same.
As you can see, I have two .dex files with very low references.
I don't understand what's happening here..
The reason why I'm trying to disable MultiDex is,
First, my app is really simple with a few dependencies so just don't need it.
Second, the app needs to support even older Android OS.
Third, I want to avoid the Dalvik linearAlloc limitation in the old Android devices.
Finally, I want to know the exact cause of this.
One more fun fact.
I decompiled and looked into the the apk file, and couldn't find the class named MainActivity which was created by default while the app ran on my phone as expected.
The same is true for my real project. The app works well but there isn't my code in the classes*.dex. Yeah, it's fine if the app works without any problem, but it's somewhat annoying because I sometimes want to decompile and see the resulted code.
Things like Instant Run change the nature of the APK. What you get when you run the app from the IDE is different than what you get when you build the app by other means (Build APK(s) in the menu, gradle tasks, etc.).
This is one of the reason why I disable Instant Run, as I'm one of those crazy people who wants to run the same app that my users would run.
Android Studio 3.0 makes another change to the APK, compared to what your users will run: it adds android:testOnly="true", preventing that APK from being installed normally. Probably this is a safety measure, so that you only distribute APKs made through some other build mechanism.
In your case, based on the comments, it appears that Instant Run was what was causing the multidex-style behavior. That may be tied to how Instant Run attempts to patch an already-installed APK, rather than push the fresh APK to the device or emulator.
So, either disable Instant Run or don't analyze the Run output, but instead focus on APKs built by other means.
I am working with ccr4j API in Android so when I run my project its thrown an error like:
Error while installing application (INSTALL_FAILED_DEXOPT)
I find from net and same site also, did all trying like,
1. Uninstalled same application from device.
2. Run Emulator with Wipe User Data.
But still same error comes.
So anyone know why its thrown this kind of error?
This most likely has to do with the size of classes.dex. On anything pre-ICS dexopt will fail on anything over 5mb. Check the size of classes.dex in your apk. It would also be good to see what your method count is as dex has a 65536 method/field limit.
I have same problem. Checked classes.dex file and it is about 7mb's. I'll try to find a solution. I hope Facebook's solution solves mine too.
By the way thanks for information #Jared.
https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920
Edit 1: I've solved this problem by using proguard optimization. My previous classes.dex file was about 7mb, and after proguard optimization it became 4mb. And now I can run this obfuscated and optimized apk on 2.2 and 2.3 devices.
Edit 2: Official Google Multi Dex support is the best solution for this issue. https://developer.android.com/tools/building/multidex.html
Find Android SDK folder. (Usually C:\User\AppData\Local\Android\sdk) Delete folders which starts with dot(.), they are temporary downloads files. Then delete Android Emulator from SDK Manager. Then run Android Studio as administrator and then download and install Android Emulator again. And make sure you have installed Intel H.A.X.M.. Now you can create emulator and use it without errors.
I have Eclipse with Android set up. The problem is when ever I run a project from eclipse to test it, the application never launches and the emulator never shows up. Even though the launching progress bar shows 100%.
Make sure the AVD's memory is set to 512, if it's higher the emulator will get a memory heap error and fail. Also try to enable verbose output when building, this can be set from within the properties.
Do you have a device attached? Eclipse switches to mobile devices automatically
I had once or twice had such problem. Restart of eclipse worked for me. And Yes also check the Run configuration, make sure your project is linked with emulator.
Go to Window->Preferences->Android->Build and select verbose build output
Now run your project and check Android console. In my case there were thousands of
"Dx processing %classname%..." which took several minutes to finish.
Just to make it clear: dx.bat is an ADT utility program, it converts multiple Java class-files to single "classes.dex" file(Dalvik executable file).
I had a project which used several libraries with lot of classes and the compilation was very fast(several seconds), but the launching was quite slow(2-4 minutes).
Then I found out that the most time consuming part was converting class files from my project and from all third-party libraries to *.dex file(the resulting size of dex-file was about 4 Mb). As far as I know, it's impossible to attach libraries to android project without dexing their class-files, so you have to be patient during launching your project.
UPD: It's possible to strip all unused code from your application.
Please check this link: Always running proguard before Android dex'ing in Eclipse
java.lang.RuntimeException: Unable to start activity....java.lang.ClassCastException: android.widget.RelativeLayout
I got this exception out of nowhere; this happens when I was actually trying to activate a new activity which, a second ago, ran fine. I tried everything, force stop the app, uninstall the app, restart eclipse, restart computer, none of which works. Then it occurred it me that there was a time when I fixed a problem like this by just closing the layout XML file and reopening it. So I tried that, and it didn't work. So I tried the one last thing: I copied out the layout XML file's content, deleted the XML file, and created another XML layout file with the same name, copied the stuff back in, and it worked! How could this be? Is it a bug of the eclipse plugin? It cost me 3 hours just to find this nonsense; I'm pissed.
I've seen that exception when I was editing some smali files and repackaging the apk. In those cases, the problem was that resources.arsc was zipped with compression instead of stored. Sometimes that messes up all the xml structure and android is unable to read it correctly. It could be some weird Eclipse bug when repackaging the apk, and it would not be the only one. From time to time, I get and error exclamation mark in one of the android projects, usually one that I did not touch in a while. I don't really know what triggers that, though.
I ran into this problem using both IntelliJ and Ant to build a package. It didn't matter if it was a debug version or signed release version both failed on startup. However, after running ant clean everything began working again.