0

I am generating singed apk using eclipse Export Signed Application Package. After generating signed apk i have installed that into my device at that time I got unfortunately stopped exception this occurs due to ClassNotFoundException. This Exception occurs only with signed apk. Normal installation working fine.

My Error Log

05-14 18:48:39.561: E/AndroidRuntime(15982): FATAL EXCEPTION: main
05-14 18:48:39.561: E/AndroidRuntime(15982): java.lang.RuntimeException: Unable to instantiate application com.yyy.android.xxx.MyApplication: java.lang.ClassNotFoundException: com.yyy.android.xxx.MyApplication
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3982)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.ActivityThread.access$1300(ActivityThread.java:127)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.os.Looper.loop(Looper.java:137)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.ActivityThread.main(ActivityThread.java:4503)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at java.lang.reflect.Method.invokeNative(Native Method)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at java.lang.reflect.Method.invoke(Method.java:511)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at dalvik.system.NativeStart.main(Native Method)
05-14 18:48:39.561: E/AndroidRuntime(15982): Caused by: java.lang.ClassNotFoundException: com.yyy.android.xxx.MyApplication
05-14 18:48:39.561: E/AndroidRuntime(15982):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.Instrumentation.newApplication(Instrumentation.java:942)
05-14 18:48:39.561: E/AndroidRuntime(15982):    at android.app.LoadedApk.makeApplication(LoadedApk.java:477)

My Manifest:

<application
        android:name=".MyApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:logo="@drawable/title_logo"
        android:theme="@style/Theme.App" >

        <!-- Tablet Starts -->

        <activity
            android:name=".ui.StartActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="landscape"
            android:theme="@style/Theme.App" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

I have selected check boxes Android Private Libraries and Android Dependencies under Order and Exports tag. And I used proguard.cfg it contains -keep public class * extends android.app.Application. I unselected check box Run full check when exporting under Lint Error Checking. Please help me to get signed apk without any issue. Thank You.

SathishKumar
  • 1,644
  • 1
  • 14
  • 28

2 Answers2

0

Ensure you have this on your proguard file -keep public class * extends android.app.Application like this:

 -keep public class * extends android.app.Activity
 -keep public class * extends android.app.Application
 -keep public class * extends android.app.Service
 -keep public class * extends android.content.BroadcastReceiver
 -keep public class * extends android.content.ContentProvider
 -keep public class * extends android.app.backup.BackupAgentHelper
 -keep public class * extends android.preference.Preference
 -keep public class * extends android.support.v4.app.Fragment
 -keep public class * extends android.widget.BaseAdapter
 -keep class com.android.vending.billing.**

and make sure your proguard file is really being used.

Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
  • yeah all are exists in proguard and proguard in use only – SathishKumar May 14 '14 at 13:53
  • nothing strange...in this case i think there's some problem on the execution of the export of APK...check out this other post and try the various techniques that suits you best: http://stackoverflow.com/questions/4600891/how-to-build-an-apk-file-in-eclipse – Alécio Carvalho May 15 '14 at 08:19
  • Yeah sure let i try these things. Thank you for your guidance – SathishKumar May 15 '14 at 08:44
0

I had the same problem after disabling minifyEnabled true fixed the problem. if the problem only exist on signed apk. check buildtypes release on module.gradle

 buildTypes {
    release {
     // minifyEnabled true

    }
}
APP Bird
  • 1,371
  • 1
  • 20
  • 37