59

I've recently updated Android SDK & Eclipse ADT plugin to latest version. Now when i try to run a pre-existing Android project, the LogCat shows a ClassNotFoundException.

I tried to create a new device but the problem still exists.

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.myapp.MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

LogCat

05-17 13:09:56.357: E/AndroidRuntime(969): FATAL EXCEPTION: main
05-17 13:09:56.357: E/AndroidRuntime(969): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myapp/com.example.myapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.myapp.MainActivity" on path: /data/app/com.example.myapp-1.apk
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.os.Looper.loop(Looper.java:137)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.ActivityThread.main(ActivityThread.java:5041)
05-17 13:09:56.357: E/AndroidRuntime(969):  at java.lang.reflect.Method.invokeNative(Native Method)
05-17 13:09:56.357: E/AndroidRuntime(969):  at java.lang.reflect.Method.invoke(Method.java:511)
05-17 13:09:56.357: E/AndroidRuntime(969):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-17 13:09:56.357: E/AndroidRuntime(969):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-17 13:09:56.357: E/AndroidRuntime(969):  at dalvik.system.NativeStart.main(Native Method)
05-17 13:09:56.357: E/AndroidRuntime(969): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myapp.MainActivity" on path: /data/app/com.example.myapp-1.apk
05-17 13:09:56.357: E/AndroidRuntime(969):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-17 13:09:56.357: E/AndroidRuntime(969):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-17 13:09:56.357: E/AndroidRuntime(969):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-17 13:09:56.357: E/AndroidRuntime(969):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
05-17 13:09:56.357: E/AndroidRuntime(969):  ... 11 more

I noticed that the new APK file is called myapp-1.apk, while it was usually called myapp.apk. Can someone tell me how to fix?

user2340612
  • 10,053
  • 4
  • 41
  • 66

4 Answers4

137

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. Clean all projects afterwards and see what happens.

Krauxe
  • 6,058
  • 2
  • 24
  • 22
  • 3
    what's about Android Private Libraries ? Has it been introduced with the last ADT? – Blackbelt May 17 '13 at 13:28
  • 1
    Thanks, that worked! @blackbelt it's the support library that has been renamed! – user2340612 May 17 '13 at 13:29
  • 20
    I second @blackbelt's question. And is there really nowhere that Google tells us about new features and breaking changes of ADT releases? ADT 22 hasn't been the total nightmare that ADT 20 was, but why not tell us about breaking changes at least? [The ADT Plug-in page](http://developer.android.com/tools/sdk/eclipse-adt.html) is where I would have expected to find it. – Tom May 21 '13 at 20:33
  • 10
    That's great that the top engineers in the world (Google) introduce updates that break stuff. Sorry can't help feeling snarky. Would be lost without stack. – Fraggle Jun 05 '13 at 16:08
  • Yes the problem is introduced in ADT 22. Google changed the container for external libraries in v22 of the ADT. Unless the applications are updated, they will experience errors similar to the above asked one. Also make sure to check the external library jar files too that you have added in your libs folder, in case you are working with external libs like ad network or any other jar files. – user632905 Jul 10 '13 at 08:32
  • Didn't work for me. After I updated the ADT I had this error and nothing seems to be wrong with my project. Android Private Libraries is already checked on my project properties. – Neon Warge Apr 11 '15 at 02:24
  • 2
    Where is this **Project** option? I'm using Android Studio 2.1.1 and I can't seem to follow this answer. – Supreme Dolphin Jun 17 '16 at 17:46
  • Where is this **Project** option? I'm using Android Studio 2.1.1 and I can't seem to follow this answer. – Supreme Dolphin Jun 17 '16 at 17:46
1

I know I'm very late to post a reply here. The workaround mentioned by Krauxe didn't help me. My project has two library projects and two jars. I found a solution posted by "laaptu" in the page Libraries do not get added to APK anymore after upgrade to ADT 22.

Community
  • 1
  • 1
Vysakh Prem
  • 93
  • 1
  • 12
1

I have the Eclipse ADT bundle and additional to the @Krauxe's answer, updating the Eclipse .project file as below worked for me:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>RedbeaconPro</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>com.android.ide.eclipse.adt.ApkBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>
jaxvy
  • 5,040
  • 1
  • 21
  • 22
0

If you are using Maven plugin in your project as well, "Maven -> Maven Update..." may cause the same problem that ClassNotFoundException. As you know, the default classes output folder should be /bin/classes which is specified in .classpath file and Eclipse Build Path. But once you do "Maven->Maven Update...", the output folder would be set as "target/classes". You can find it(output="target/classes") in your .classpath file.

.classpath file:

...    
<classpath>
            <classpathentry kind="src" path="gen"/>
            <classpathentry kind="src" output="target/classes" path="src/main/java">
...

How to resolve this problem, please explicitly specify the classes output folder as "bin/classes" in pom.xml file.

pom.xml file:

...
<build>
            <sourceDirectory>src/main/java</sourceDirectory>
            <outputDirectory>bin/classes</outputDirectory>
...
Richard
  • 2,080
  • 18
  • 17