3

I've moved from Mac to a linux machine (ubuntu) and and can't get the previous project running. The project has about 10 modules, and it still works fine on my macbook, but when building on ubuntu (tried clean install on 17.10 2 times, and 16.04 2 times as well) will crash the app on start with the following error:

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application com.xxx.xxx.Application: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.Application" on path: DexPathList[[zip file "/data/app/com.xxx.xxx.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx.debug-1/lib/arm, /data/app/com.xxx.xxx.debug-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5418)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1558)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.Application" on path: DexPathList[[zip file "/data/app/com.xxx.xxx.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx.debug-1/lib/arm, /data/app/com.xxx.xxx.debug-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newApplication(Instrumentation.java:1014)
at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5418) 
at android.app.ActivityThread.-wrap2(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1558) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6165) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778) 

I've tried cleaning, rebuilding, invalidating and restarting, 3 different android studio versions (the stable one, 2.3, and latest canary build) on both operating systems (17.10 and 16.04) and I still get exactly same error. Also, I've installed the libraries for 64 bit system. Also, I've tried with oracle java as well.

Does anyone have any clue why a project gets this error on linux but not on mac?


Update

So I found out that Ubuntu does not see the application class. It has a red label and is not recognized from the manifest file. This is the application class from app package and I can only see it if I switch to project view. I'm currently investigating why it doesn't see it.

Filip Luchianenco
  • 6,912
  • 9
  • 41
  • 63
  • are the Platform Images properly installed? the stacktrace shows something related to `armeabi-v7a`. Can you make sure those system images are installed – Rinav Dec 14 '17 at 05:05
  • In all use cases, I can start hello world app and everything is fine. If that answers the question – Filip Luchianenco Dec 14 '17 at 05:09
  • looking at the log, I guess the problem is with some of your libraries or your build path they are pointing towards your old path so android is unable to find it. Take a look at these questions maybe they will help you. https://stackoverflow.com/questions/22399572/java-lang-classnotfoundexception-didnt-find-class-on-path-dexpathlist https://stackoverflow.com/questions/10866431/android-activity-classnotfoundexception-tried-everything?rq=1 – Umair Dec 14 '17 at 05:19
  • I thought about that as well. But there are over 7 devs working on this project as well, and everything works good for them. They are all on osx as well. – Filip Luchianenco Dec 14 '17 at 05:23
  • @FilipLuch i am sure the problem is either with some library or the build path. As you can see from the log that it can't find the specific file/class. And if it was with your tool then hello world also wouldn't start either. – Umair Dec 14 '17 at 05:38
  • add `multiDexEnabled true` – IntelliJ Amiya Dec 14 '17 at 05:38
  • I see what you mean @umair but how could I find what caused it? – Filip Luchianenco Dec 14 '17 at 05:40
  • can you tell on how many devices/emulators did you tried to run you app ? – Umair Dec 14 '17 at 05:44
  • 2 emulators, 3 devices. Various versions – Filip Luchianenco Dec 14 '17 at 05:49
  • Like intellij Amiya said have you enabled multiDexEnabled ? and also declared in dependencies and your manifest ? – Umair Dec 14 '17 at 05:51
  • Yeah, of course. Multidex has been added correctly. It works fine on Mac, and for all other devs. – Filip Luchianenco Dec 14 '17 at 05:52
  • 1
    @Umair I just updated the question with more details on the issue. – Filip Luchianenco Dec 14 '17 at 15:36

2 Answers2

1

So the problem was that Ubuntu would not see the Application class, and thus did not consider it on build, as a result it wasn't included in dex files. The thing is that the application class is inside app -> src -> main -> Java -> packagename -> Application.class , and Ubuntu did not recognize Java as a valid directory. It recognizes it only if it is java. So renaming the folder Java to java has fixed the problem and the application class is now visible.

Morale 1: Always triple check all ridiculous use cases and pay attention to details.

Morale 2: Ubuntu handles folders in a different manner than Mac because Mac couldn't care less if that's capital J or lowercase j.

Filip Luchianenco
  • 6,912
  • 9
  • 41
  • 63
0

Do one thing disable Instant Run feature.

you can do it by

File->Settings->Build,Execution,Deployment->Instant run

Click on instant run and then disable the checkbox for Instant Run.

Shivam Oberoi
  • 1,447
  • 1
  • 9
  • 18