2017-03-08 63 views
4

我已經搜索瞭解決方案,並且有幾個和SO類似的ClassNotFoundException線程。但我嘗試瞭解決方案,沒有任何幫助。所以在我的情況下,直接從Android Studio將應用程序部署到設備時,它運行正常,但從文件安裝時崩潰:adb install app-debug.apk路徑中未找到.MyApp類:DexPathList。只有在直接運行debug apk的情況下

03-08 16:45:59.303 32233-32233/us.kostenko.glagol.debug E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: us.kostenko.glagol.debug, PID: 32233 
                      java.lang.RuntimeException: Unable to instantiate application us.kostenko.glagol.di.application.MyApp: java.lang.ClassNotFoundException: Didn't find class "us.kostenko.glagol.di.application.MyApp" on path: DexPathList[[zip file "/data/app/us.kostenko.glagol.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/us.kostenko.glagol.debug-1/lib/arm64, /vendor/lib64, /system/lib64]] 
                       at android.app.LoadedApk.makeApplication(LoadedApk.java:565) 
                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4561) 
                       at android.app.ActivityThread.access$1500(ActivityThread.java:154) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:135) 
                       at android.app.ActivityThread.main(ActivityThread.java:5298) 
                       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:913) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:708) 
                      Caused by: java.lang.ClassNotFoundException: Didn't find class "us.kostenko.glagol.di.application.MyApp" on path: DexPathList[[zip file "/data/app/us.kostenko.glagol.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/us.kostenko.glagol.debug-1/lib/arm64, /vendor/lib64, /system/lib64]] 
                       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.newApplication(Instrumentation.java:980) 
                       at android.app.LoadedApk.makeApplication(LoadedApk.java:560) 
                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4561)  
                       at android.app.ActivityThread.access$1500(ActivityThread.java:154)  
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)  
                       at android.os.Handler.dispatchMessage(Handler.java:102)  
                       at android.os.Looper.loop(Looper.java:135)  
                       at android.app.ActivityThread.main(ActivityThread.java:5298)  
                       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:913)  
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:708)  
                      Suppressed: java.lang.ClassNotFoundException: us.kostenko.glagol.di.application.MyApp 
                       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 

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="us.kostenko.glagol"> 

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

<!-- For download manager --> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

<application 
    android:name=".di.application.MyApp" 
    android:allowBackup="false" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".SplashActivity" 
     android:theme="@style/SplashTheme"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".MainActivity" 
     android:label="" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:screenOrientation="portrait" 
     android:launchMode="singleTop"> 
    </activity> 
    <activity 
     android:name=".personal.SignInActivity" 
     android:label="@string/title_activity_sign_in" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:screenOrientation="portrait"/> 
    <activity 
     android:name=".payment.PaymentActivity" 
     android:label="@string/title_activity_payment" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:screenOrientation="portrait"> 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value=".MainActivity" /> 
    </activity> 
    <service 
     android:name=".catalog.service.BookFilesService" 
     android:exported="false" 
     android:description="@string/about_detail_book_service"/> 
    <service 
     android:name=".player.PlayerService" 
     android:exported="false" 
     android:description="@string/about_play_book_service"/> 
</application> 

和的build.gradle:

apply plugin: 'com.android.application' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-android-extensions' 
apply plugin: 'kotlin-kapt' 
apply plugin: 'realm-android' 

Properties properties = new Properties() 
properties.load(project.rootProject.file('local.properties').newDataInputStream()) 
def superpowered_sdk_path = properties.getProperty('superpowered.dir') 

android { 
    signingConfigs { 
     config { 
      ... 
     } 
    } 
    compileSdkVersion rootProject.compileSdkVersion 
    buildToolsVersion rootProject.buildToolsVersion 
    defaultConfig { 
     applicationId "us.kostenko.glagol" 
     minSdkVersion rootProject.minSdkVersion 
     targetSdkVersion rootProject.targetSdkVersion 
     versionCode 2 
     versionName "1.1" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

     ndk { 
      abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 
      // these platforms cover 99% percent of all Android devices 
     } 

     externalNativeBuild { 
      cmake { 
       arguments '-DANDROID_PLATFORM=android-16', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_ARM_NEON=TRUE', '-DANDROID_STL=gnustl_static', "-DPATH_TO_SUPERPOWERED:STRING=${superpowered_sdk_path}" 
       cFlags '-O3', '-fsigned-char' // full optimization, char data type is signed 
       cppFlags '-fsigned-char', "-I${superpowered_sdk_path}" 
      } 
     } 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
     debug { 
      applicationIdSuffix ".debug" 
     } 
    } 
    sourceSets { 
     main.java.srcDirs += 'src/main/kotlin' 
     main { 
      jniLibs.srcDirs = ['src/main/jni'] 
     } 
    } 
    externalNativeBuild { 
     cmake { 
      path 'src/main/jni/CMakeLists.txt' 
     } 
    } 
} 

kapt { 
    generateStubs = true 
} 

repositories { 
// maven { url 'https://github.com/linchaolong/stetho-realm/raw/master/maven-repo' } 
    mavenCentral() 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    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:$rootProject.ext.supportLibraryVersion" 
    compile "com.android.support:design:$rootProject.ext.supportLibraryVersion" 
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9' 


    testCompile 'junit:junit:4.12' 
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 
    /* Rx - reactive extensions 
       https://github.com/ReactiveX/RxAndroid */ 
    compile 'io.reactivex:rxandroid:1.2.1' 
    compile 'io.reactivex:rxjava:1.1.6' 
    /* Retrofit - networking 
       * http://square.github.io/retrofit/ */ 
    compile "com.squareup.retrofit2:retrofit:$rootProject.ext.retrofit2Version" 
    compile "com.squareup.retrofit2:converter-gson:$rootProject.ext.retrofit2Version" 
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 
    /* Gson - json parsing 
       * https://github.com/google/gson */ 
    compile 'com.google.code.gson:gson:2.7' 
    /* OkHttp3 - http client 
       * http://square.github.io/okhttp/ */ 
    compile "com.squareup.okhttp3:okhttp:$rootProject.ext.okhttpVersion" 
    compile "com.squareup.okhttp3:logging-interceptor:$rootProject.ext.okhttpVersion" 
    /* Dagger 2 - DI 
       https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2*/ 
    compile 'com.google.dagger:dagger:2.8' 
    kapt "com.google.dagger:dagger-compiler:2.4" 
    provided 'org.glassfish:javax.annotation:10.0-b28' 

    /* Glide - image loading lib 
       https://github.com/bumptech/glide */ 
    compile 'com.github.bumptech.glide:glide:3.7.0'integration:[email protected]' 
    compile "com.android.support:support-v4:$rootProject.ext.supportLibraryVersion" 
    /* Realm */ 
    compile 'io.realm:android-adapters:1.3.0' 

    compile 'de.cketti.mailto:email-intent-builder:1.0.0' 
    compile 'com.roughike:bottom-bar:2.1.1' 
} 
repositories { 
    mavenCentral() 
} 

我有在項目類MyApp的。那個日誌對我來說沒有任何意義。在將Android Studio更新到2.3並更新項目中的某些依賴項後,我發現了這個問題。在它工作正常之前。

我將不勝感激任何幫助解決這個問題。

編輯: 經過一些試驗後,我發現我創建構建的方式有所不同。如果我使用Build/Build APK和adb install app-debug.apk構建我的項目,它不會拋出異常。但每次我使用運行/運行「應用程序」選項將應用程序部署到設備時,安裝apk通過終端結果以這種方式創建的方式與上述異常崩潰。它是打算行爲還是錯誤?

另外值得注意的是,Build/Clean項目修復了下一個版本的問題。

回答

1

這是一個預期的行爲。如果啓用了即時運行功能,那麼只會在最近發生的變化時,AS纔會構建特殊類型的apk。所以,爲了構建一個能夠使用adb install app-debug.apk命令運行的apk,你應該使用Build/Build APK構建一個apk。

相關問題