出现此错误时如何修复gradle?

Posted

技术标签:

【中文标题】出现此错误时如何修复gradle?【英文标题】:How to fix gradle when this error appear? 【发布时间】:2019-07-11 14:43:47 【问题描述】:

我开始了一个新项目并放了火基云:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android 
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig 
        applicationId "android.example.com.squawker"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    


dependencies 
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', 
        exclude group: 'com.android.support', module: 'support-annotations'
    )
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'

// RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'

// Schematic dependencies for ContentProvider
apt 'net.simonvt.schematic:schematic-compiler:0.6.3'
implementation 'net.simonvt.schematic:schematic:0.6.3'

// Preferences Dependencies
implementation 'com.android.support:preference-v7:28.0.0'

// Firebase dependency
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

// Apply the Google Services plugin. Make sure to add the google-services.json file in the app
// folder. You download it from the Firebase console
apply plugin: 'com.google.gms.google-services'

这个错误出现了:

警告:API 'variant.getJavaCompile()' 已过时,已替换为 'variant.getJavaCompileProvider()'。 它将在 2019 年底被删除。 有关详细信息,请参阅https://d.android.com/r/tools/task-configuration-avoidance。 要确定调用 variant.getJavaCompile() 的内容,请在命令行上使用 -Pandroid.debug.obsoleteApi=true 以显示堆栈跟踪。 受影响的模块:app

【问题讨论】:

【参考方案1】:

这可能是因为apt plugin which is already obsolete。因此,您需要删除以下内容:

apply plugin: 'android-apt'

然后更改以下内容:

apt 'net.simonvt.schematic:schematic-compiler:0.6.3'

与:

annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.6.3'

【讨论】:

做了,同样的问题出现了。【参考方案2】:

类似于API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()快乐编码!

【讨论】:

以上是关于出现此错误时如何修复gradle?的主要内容,如果未能解决你的问题,请参考以下文章

将eclipse导入android studio时如何修复错误?(作为build.gradle的编译时依赖项)

如何修复错误 - 执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障

如何修复 Android Studio 中的 INSTALL_FAILED_INVALID_APK 错误?

我在构建APK时遇到错误

如何修复“任务 'compileJava' 执行失败”错误。 (使用 Intellij Idea 和 Gradle)

如何使用Android Studio解决抖动中的gradle错误?