2017-04-27 98 views
1

我在Windows 10上使用的是Android studio 2.3.1當我嘗試在設備上運行該應用程序時,當我的設備連接到android studio時,則能夠運行應用程序。但是,當我試圖安裝在Android手機上的調試或發行APK則得到安裝,但在打開的應用程序它提供了以下錯誤:無法在Android手機上運行調試版的apk

04-27 10:06:31.675 30541-30541/package name E/AndroidRuntime: FATAL EXCEPTION: main 
Process: package_Name, PID: 30541 
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{package Name/package_Name.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "package_Name.SplashActivity" on path: DexPathList[[zip file "/data/app/package_Name-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376) 
at android.app.ActivityThread.access$800(ActivityThread.java:147) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5253) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 

Caused by: java.lang.ClassNotFoundException: Didn't find class "package_Name.SplashActivity" on path: DexPathList[[zip file "/data/app/package_Name-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
at android.app.Instrumentation.newActivity(Instrumentation.java:1065) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2217) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376) 
at android.app.ActivityThread.access$800(ActivityThread.java:147) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5253) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 
Suppressed: java.lang.ClassNotFoundException: package Name.SplashActivity 
at java.lang.Class.classForName(Native Method) 
at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
... 13 more 

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

任何幫助將不勝感激。 我的gradle代碼

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 
    defaultConfig { 
     applicationId "package_Name" 
     minSdkVersion 15 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'com.android.support:design:25.3.1' 
    testCompile 'junit:junit:4.12' 
} 
+0

你可以分享你的代碼的gradle? –

+0

可能是_「package Name」_應該是'com.example.SomeClassName'而不是包含空格的包名稱。 – Shashanth

+0

@Shashanth它就像「com.businessName.projectName」 – ASK

回答

-1

取消選中即時運行.. 如何做到這一點:

  1. 打開設置或首選項對話框:在Windows或Linux,選擇File >菜單欄中的設置。在Mac OSX上,從菜單欄中選擇Android Studio>首選項。
  2. 導航到構建,執行,部署>即時運行。
  3. 取消選中代碼更改重新啓動活動旁邊的複選框。
0

@ASK能否請您清理您的項目並重建它。這是錯誤大多獲得當你的apk未正確創建

+0

我已經清理了我的項目並重建了它。但錯誤仍然相同。 – ASK

+0

請驗證請求的類的名稱是否正確 – sukhbir

0

Your package name should not contain space as from your code their is space in the package name

請改變它喜歡package.name

+0

在實際項目中,包名中沒有空格 – ASK

+0

請驗證請求的類的名稱是否正確 – sukhbir

+0

是的它是正確的。當我直接從android studio運行應用程序;它是工作,但當我安裝在Android手機上的apk顯示上述錯誤。 – ASK

0

可能發生的問題,因爲你有你可能已經超過了64K的方法限制。

您應該考慮在您的應用中啓用multidex。

defaultConfig { 
    ... 
    ... 

    // Enabling multidex support. 
    multiDexEnabled true 
} 

dependencies { 
compile 'com.android.support:multidex:1.0.0' 
} 

同時添加這體現

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.android.multidex.myapplication"> 
    <application 
     ... 
     android:name="android.support.multidex.MultiDexApplication"> 
     ... 
    </application> 
</manifest> 
+0

我應用您的解決方案,但它不工作。請看行: '引起:java.lang.ClassNotFoundException:在路徑中找不到類**「com.packagename.fb.SplashActivity」**:DexPathList [[zip file **]/data/app /com.packagename.fb-1/base.apk「] **,nativeLibrary Directories = [/ vendor/lib,/ system/lib]]' – ASK

+0

您的軟件包名稱在這裏似乎有些異常。找不到類** **「com.packagename.fb.SplashActivity」**和**「/ data/app/com.packagename.fb-1/base.apk」** –

2

您可以只解決這個「生成(標籤)/建造APK」,而不是運行「應用」

相關問題