Build errors after Android Studio 3.2.1 upgrade

2019-01-13 03:47发布

I am building a sample project from Udacity. This was working fine till now, but after upgrading to Android Studio 3.2.1, I am facing the build error below.

Gradle version: 4.6

Project link: https://github.com/udacity/ud851-Sunshine/tree/student/S02.02-Solution-Menus

Could not find com.android.tools.build:aapt2:3.2.1-4818971**. Searched in the following locations:
    file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
    file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
    file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
    file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
    file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
    file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
    https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
    https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar Required by:
    project :app

How can I fix it?

7条回答
太酷不给撩
2楼-- · 2019-01-13 04:32

Add Google repository in your build.gradle(Project:xxxxx)

allprojects {
    repositories {
        google()
    }
}
查看更多
再贱就再见
3楼-- · 2019-01-13 04:33

add google() on your build script > repositories add google on allprojects > repositories

use implementation as replacement of compile keyword, also on your filetree.

EX.

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:appcompat-v7:25.3.1'
    implementation 'com.android.support:design:25.3.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4:25.3.1'
查看更多
闹够了就滚
4楼-- · 2019-01-13 04:35

Change your build.gradle as follows.

android {
    compileSdkVersion 26
    buildToolsVersion "28.0.3"

    defaultConfig {
        applicationId "your package name here"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:26.1.0'
}
查看更多
来,给爷笑一个
5楼-- · 2019-01-13 04:41

Yeah, as d4rkcon said download https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar But you can do simplier - just put this file in directory where Andoid Studio is trying to find it. If you don't have directories like /tools/build/aapt2/3.2.1-4818971/ in AndroidSDK folder just create them and then put aapt2-3.2.1-4818971-windows.jar file in.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-13 04:43

For Android Studio 3.2.1 update

Just add google() in root level in build.gradle

buildscript {
    repositories {
        google() //  <--here
        jcenter()
    }
 }

allprojects {
    repositories {
        google() //  <-- here
        jcenter()
    }
}

and see the magic - error is gone.

查看更多
疯言疯语
7楼-- · 2019-01-13 04:46

The project gradle version is pretty old:

classpath 'com.android.tools.build:gradle:2.2.3'

And you are using Android Studio v3.2.1 so, update the gradle:

classpath 'com.android.tools.build:gradle:3.2.0' // or 3.2.1 maybe

Also, as you can see, it was looking for some packages in :

file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom

Which means you probably forgot to add google() as the top level repository. Just add google()

to your repositories in your root build.gradle.

查看更多
登录 后发表回答