5

I'm currently using Android Studio to develop my own project for Android (my custom launcher)! The thing is, since last update (to version 0.4.0) I can't run my app.

Instead I get the following error:

FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.natercio.myhome/com.natercio.myhome.Launcher}: java.lang.ClassNotFoundException: Didn't find class "com.natercio.myhome.Launcher" on path: DexPathList[[zip file "/data/app/com.natercio.myhome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.natercio.myhome-2, /system/lib]]
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.natercio.myhome.Launcher" on path: DexPathList[[zip file "/data/app/com.natercio.myhome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.natercio.myhome-2, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)

I've searched everywhere I could remember for a solution (or something related) and tried a bunch of stuff already without any success.

  • check the "compiler.xml" (there are no excludes)
  • clean/build (error persists)
  • check the "AndroidManifest.xml" (everything seems correct)
  • recreated the whole project (only imported the code and the resources but the error persists)

One thing I did notice in this line

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.natercio.myhome.Launcher" on path: DexPathList[[zip file "/data/app/com.natercio.myhome-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.natercio.myhome-2, /system/lib]]

is that there is an "-2" (and sometimes a "-1") appended to the name of the app (both in the apk file and in the lib path) but I never really noticed this before so I can't tell for sure if this is somehow related with my problem.

Please also take in consideration that I use git and I've already tried to revert any changes to one of my previously stable commits.

UPDATE:

Has anyone else encountered this problem in Android Studio? Is there any other solution to this kind of error that I missed or is this likely to be some bug in the latest android plugin (for android studio).

UPDATE (build.gradle & manifest file):

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:support-v13:+'
    compile 'com.j256.ormlite:ormlite-android:4.47'
}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.natercio.myhome"
          android:versionName="@string/app_version_name">

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

    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/Theme.Launcher">

        <service android:name=".profiler.ProfilerService"
                 android:exported="false"/>

        <activity android:name=".Launcher"
                  android:screenOrientation="portrait"
                  android:launchMode="singleTask"
                  android:description="@string/app_description">

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

        </activity>

    </application>

</manifest>
prototyp3PT
  • 123
  • 1
  • 1
  • 7
  • Can you post more details on how your project is laid out, and include your build.gradle file? – Scott Barta Dec 28 '13 at 21:36
  • @ScottBarta I've included some more details! If you need more details just say so – prototyp3PT Dec 29 '13 at 15:25
  • I'm having the same problem after updating to 0.4.0. Every time I update Android Studio, I wonder why I use this for production work. :) – Brian Jan 03 '14 at 18:34

6 Answers6

2

I was having this same issue after updating Android Studio to 0.4.0. It seems overly-simplistic, but I solved the issue by simply deleting my whole /build folder (the one created before the 0.4.0 update) and rebuilding.

Brian
  • 1,436
  • 8
  • 18
2

try this java.lang.RuntimeException: Unable to instantiate activity ComponentInfo / java.lang.ClassNotFoundException

or, use the CMD to access the project and Clean your project

gradlew clean

gradlew build

Community
  • 1
  • 1
toufik3119
  • 115
  • 1
  • 3
  • 12
0

the -2 or -1 come from having multiple copies I believe? At least that's what it has been in my experience. But what exactly is your question here?

  • I've updated the post! You say "-#" stands for multiple copies, but of what and where precisely (device or development machine) – prototyp3PT Dec 27 '13 at 21:27
  • development machine. If you didn't put it there. The program is probably using some type of naming convention for multiple files of the same name. – Learning2network Dec 30 '13 at 17:55
0

The error is stating that it there are multiple copies of one of the library that you are using in your project. Go into the project structure -> modules and check in the target or the apk-libs folder if android studio is extracting more than one copies. I had the same error in android studio and it turned out studio was generating a new folder in the target folder called unpack which was causing the problem.

user2511882
  • 9,022
  • 10
  • 51
  • 59
0

The problem fixed itself after some updates to android studio!

prototyp3PT
  • 123
  • 1
  • 1
  • 7
0

Check your project setting->modules->your project name->sources

make sure your src and res list on right frame (named Add Content Root, res as Resources Folders, src as Sources Folders)

or your project encounter some errors, the stupid android studio still put the wrong apk on your device and run of course got the error.

Chris Ho
  • 295
  • 4
  • 13