将Android Studio项目从Windows移动到Mac后的ClassNotFoundException(AppCompatActivity.class)

时间:2017-05-10 13:15:07

标签: java android macos android-studio android-support-library

:)

我目前正在使用Android Studio开发Android应用程序,在我的Windows机器上工作了很长时间之后,我正在尝试在MacBook Air上运行它。

我复制了项目文件并在Mac上创建了一个模拟器(API 25)。该项目编译得很好,但由于以下错误,它会立即在仿真器上崩溃:

FATAL EXCEPTION: main
                                                                       Process: com.lennartschoch.partytime, PID: 5736
                                                                       java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.lennartschoch.partytime/com.lennartschoch.partytime.LoadingActivity}: java.lang.ClassNotFoundException: Didn't find class "com.lennartschoch.partytime.LoadingActivity" on path: DexPathList[[zip file "/data/app/com.lennartschoch.partytime-2/base.apk", zip file "/data/app/com.lennartschoch.partytime-2/split_lib_slice_3_apk.apk"],nativeLibraryDirectories=[/data/app/com.lennartschoch.partytime-2/lib/x86, /system/lib, /vendor/lib]]
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                        Caused by: java.lang.ClassNotFoundException: Didn't find class "com.lennartschoch.partytime.LoadingActivity" on path: DexPathList[[zip file "/data/app/com.lennartschoch.partytime-2/base.apk", zip file "/data/app/com.lennartschoch.partytime-2/split_lib_slice_3_apk.apk"],nativeLibraryDirectories=[/data/app/com.lennartschoch.partytime-2/lib/x86, /system/lib, /vendor/lib]]
                                                                           at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                           at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                                                                           at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:154) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
                                                                        Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/app/AppCompatActivity;
                                                                           at java.lang.VMClassLoader.findLoadedClass(Native Method)
                                                                           at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:742)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:362)
                                                                                ... 12 more
                                                                        Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatActivity" on path: DexPathList[[zip file "/data/app/com.lennartschoch.partytime-2/base.apk", zip file "/data/app/com.lennartschoch.partytime-2/split_lib_slice_3_apk.apk"],nativeLibraryDirectories=[/data/app/com.lennartschoch.partytime-2/lib/x86, /system/lib, /vendor/lib]]
                                                                           at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                           at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                ... 15 more

我(希望)目前已经实现了Android支持库(v7),您可以在我的build.gradle中看到:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.lennartschoch.partytime"
        minSdkVersion 19
        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(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:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
}

我已经尝试过清理和重建项目,但我无法摆脱这个问题。有什么建议吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

**C:\Users(user)\AppData\Roaming\npm\node_modules\webdriver-manager\built\lib\cli\logger.js:66
info(...msgs) {
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. (C:\Users(user)\AppData\Roaming\npm\node_modules\we
bdriver-manager\built\lib\cli\index.js:8:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)**

使用这些依赖项。

答案 1 :(得分:0)

将Android项目移动到旧目录的子目录后,我遇到了同样的问题。首先,当我尝试在早期的同一设备上运行项目时,我收到以下错误:

DELETE_FAILED_INTERNAL_ERROR
Error while Installing APKs

我通过执行Build -> Clean Project摆脱了这一点,但后来我得到了这些ClassNotFound例外,应用程序立即崩溃了。这是通过在项目根目录中的终端中运行gradlew clean并再次构建来解决的。