Android 使用Gradle插件3.1.2改进2.4.0

Android 使用Gradle插件3.1.2改进2.4.0,android,gradle,retrofit2,Android,Gradle,Retrofit2,我有一个非常简单的问题。我是一名Android开发人员,在休息6个月后重返开发,一切都像往常一样发生了明显的变化。我的问题是: 在Android Studio 3.1.2上启动一个新的Android项目 默认的Gradle插件是3.1.2 在应用程序的build.gradle中添加了2依赖项 implementation'com.squareup.reformation2:reformation:2.4.0' 开始梯度同步 无法解析“”的依赖项:app@debug/compileClas

我有一个非常简单的问题。我是一名Android开发人员,在休息6个月后重返开发,一切都像往常一样发生了明显的变化。我的问题是:

  • 在Android Studio 3.1.2上启动一个新的Android项目
  • 默认的Gradle插件是3.1.2
  • 在应用程序的build.gradle中添加了2依赖项
implementation'com.squareup.reformation2:reformation:2.4.0'

  • 开始梯度同步
无法解析“”的依赖项:app@debug/compileClasspath:无法 未解析com.squareup.Refught2:Refught2.4.0。打开文件显示 细节

无法解析的依赖项 ':app@debugAndroidTest/compileClasspath':无法解析 改装2:改装:2.4.0。打开文件显示详细信息

无法解析的依赖项 ':app@debugUnitTest/compileClasspath':无法解析 改装2:改装:2.4.0。打开文件显示详细信息

无法解析“”的依赖项:app@release/compileClasspath': 无法解析com.squareup.Refught2:Refught2.4.0。打开文件 显示细节

无法解析的依赖项 ':app@releaseUnitTest/compileClasspath':无法解析 改装2:改装:2.4.0。打开文件显示详细信息

我读了关于Gradle插件3迁移的整篇文章。这没有帮助

projectbuild.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.xyz.xyz"
        minSdkVersion 15
        targetSdkVersion 27
        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'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
应用程序级build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.xyz.xyz"
        minSdkVersion 15
        targetSdkVersion 27
        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'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我运行您的代码时没有错误。尝试使缓存无效/从以下位置重新启动:文件->使缓存无效/重新启动

如果您的电脑正在某个代理上运行,请在android studio中添加代理或检查您的internet连接。 对于代理服务器,请执行以下步骤: 文件->设置->外观和行为->系统设置->HTTP代理 添加您的代理


否则,请检查您的internet连接

我的工作就是尝试通过“项目结构依赖项”窗口添加它 遵循以下步骤: 1-文件->项目结构->依赖项


单击“应用”,然后再次尝试同步,我觉得效果很好。

向我们显示您的项目和应用程序级别的build.gradle文件我添加了您要求的文件。其实一点也不复杂。这只是一个简单的示例项目,只是对依赖项添加了一行内容。