迁移到AndroidX后,项目构建失败

时间:2019-08-20 02:38:43

标签: android androidx

迁移到AndroidX后,我的项目无法构建,错误日志在某个类中显示error: package android.support.annotation does not exist,但是这些类无法编辑,当我编辑这些类并重新构建时,这些将被恢复。打开时,这些类别将显示Files under the "build" folder are generated and should not be edited.,而编辑时,这些类别将显示Generated source files should not be edited. The change will be lost when sources are regenerated.

我尝试清理我的项目,然后进行同步和重建,但是没有用,我该如何解决,谢谢。

这是我的错误日志:

C:/Users/Myname/AndroidStudioProjects/PGapp 
app/build/generated/source/apt/debug/com/gmpsykr/goma/GlideOptions.java 
error: package android.support.annotation does not exist    
error: package android.support.annotation does not exist    
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
error: cannot find symbol class CheckResult 
app/build/generated/source/apt/debug/com/gmpsykr/goma/GlideRequest.java 
app/build/generated/source/apt/debug/com/gmpsykr/goma/GlideRequests.java    
app/build/generated/source/apt/debug/com/bumptech/glide/GeneratedRequestManagerFactory.java 
app/build/generated/source/apt/debug/com/bumptech/glide/GeneratedAppGlideModuleImpl.java    

这是我的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId 'MyId'
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 5
        versionName "1.3"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'com.android.billingclient:billing:2.0.2'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.firebase:firebase-storage:18.1.1'
    implementation 'com.google.firebase:firebase-database:18.0.1'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.firebase:firebase-ads:18.1.1'
    implementation 'com.firebaseui:firebase-ui-storage:5.0.0'
    implementation 'com.facebook.android:audience-network-sdk:5.4.1'
    implementation 'com.facebook.android:facebook-android-sdk:5.4.0'
    implementation 'com.github.chrisbanes:PhotoView:2.1.4'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation files('libs/jsch-0.1.55.jar')
}

apply plugin: 'com.google.gms.google-services'

这是我的gradle.properties:

org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true

2 个答案:

答案 0 :(得分:1)

我认为Glide Library有问题。

您能删除这部分吗? annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

此后,您应该单击Refactor -> Migrate to AndroidX

答案 1 :(得分:0)

将此添加到应用gradle文件

annotationProcessor'androidx.annotation:annotation:1.0.0'