Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with running Android APK file when merging dex files using Scala

I've been trying to create Android applications using Scala 2.9.1 and SBT 0.13 and Android-Plugin.
However, running ProGuard can be extremely slow.
So, instead, when I'm not using any new classes/methods since the previous build, I'm just trying to merge classes.dex with my own dexed android-app classes (like MainActivity.scala and such).

The problem I get (on Android 4.0.x) is that the merging goes without any errors, but when I try to run the application, I get this "Unfortunately, MyAndroidApp has stopped".

Here's the logcat log:

  EmbeddedLogger  E  App crashed! Package: com.my.app v0 (0.1)
  300         EmbeddedLogger  E  Application Label: MyAndroidApp
 24137        AndroidRuntime  E  FATAL EXCEPTION: main
 24137        AndroidRuntime  E  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.my.app/com.my.app.MainActivity}: java.lang.ClassNotFoundException: com.my.app.MainActivity
 24137        AndroidRuntime  E   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2118)
 24137        AndroidRuntime  E   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
 24137        AndroidRuntime  E   at android.app.ActivityThread.access$600(ActivityThread.java:139)
 24137        AndroidRuntime  E   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
 24137        AndroidRuntime  E   at android.os.Handler.dispatchMessage(Handler.java:99)
 24137        AndroidRuntime  E   at android.os.Looper.loop(Looper.java:156)
 24137        AndroidRuntime  E   at android.app.ActivityThread.main(ActivityThread.java:5005)
 24137        AndroidRuntime  E   at java.lang.reflect.Method.invokeNative(Native Method)
 24137        AndroidRuntime  E   at java.lang.reflect.Method.invoke(Method.java:511)
 24137        AndroidRuntime  E   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
 24137        AndroidRuntime  E   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
 24137        AndroidRuntime  E   at dalvik.system.NativeStart.main(Native Method)
 24137        AndroidRuntime  E  Caused by: java.lang.ClassNotFoundException: com.my.app.MainActivity
 24137        AndroidRuntime  E   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
 24137        AndroidRuntime  E   at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
 24137        AndroidRuntime  E   at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
 24137        AndroidRuntime  E   at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
 24137        AndroidRuntime  E   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2109)
 24137        AndroidRuntime  E   ... 11 more
  300        ActivityManager  W    Force finishing activity com.my.app/.MainActivity
  5864        OpenGLRenderer  D  Flushing caches (mode 1)
  300           ViewRootImpl  D  @@@- disable SystemServer HW acceleration

I have manually opened the generated apk, and classes.dex inside it, navigated thru the packages and found MainActivity there.

Any help will be greatly appreciated.

like image 931
ioreskovic Avatar asked Oct 22 '22 16:10

ioreskovic


2 Answers

OK, I figured what was wrong.

By definition, every Scala class implements scala.ScalaObject.
My dexed com.my.app.MainActivity also implemented scala.ScalaObject.

However, since I didn't have scala.ScalaObject as a part of my previous classes.dex file, and I didn't include it in the new one, DVM coulnd't find a class with the signature of public class com.my.app.MyAndroidApp extends android.app.Activity implements com.my.app.TypedActivity with scala.ScalaObject.

like image 83
ioreskovic Avatar answered Nov 03 '22 06:11

ioreskovic


My best guess is that dalvik is rejecting the class for some reason. You want to look in logcat around the time you were installing the application, and look for any messages from dalvik. It will print a brief blurb about what class it is rejecting and why.

like image 22
JesusFreke Avatar answered Nov 03 '22 04:11

JesusFreke