简体   繁体   中英

Gradle build in Android Studio

I updated my Android Studio to version 3.0.1, and then Gradle to 4.2 and Android plugin tools to 3.0.1. After that whenever I create a new project it gives me the Gradle build problem. This is my module build.gradle:

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
    applicationId "com.nasser.studio.test"
    minSdkVersion 14
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
   compile  fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile  'com.android.support:appcompat-v7:27.0.3'
}

Also I unchecked the work offline for gradle.

在此处输入图片说明

I also checked AS settings which displays some errors:

在此处输入图片说明

Update 1: When I change the compile SDK to version 25 like this, the Gradle build is completed correctly.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.nasser.studio.test"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:25.3.1'
}

But changing to latest versions (26 or 27), it gives me the same error. I also should mention that during Gradle build process for these versions, it's downloading files from Maven repositories which doesn't happen in version 25 ( I'm using a proxy connection).

在此处输入图片说明

Moreover, the search box of AS for support library gives me this version which is not the latest version (27.0.2).

在此处输入图片说明

Add this to your project level build.gradle file:

allprojects {
repositories {
    maven {
        url 'https://maven.google.com'
    }
}
}

Change this on your Project level build.gradle

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

You should use stable v7:27.0.2 instead off v7:27.0.3 .

implementation "com.android.support:appcompat-v7:27.0.2"

FYI

If you are using Android Studio 3.0 or above make sure , your build.gradle (PROJECT level) file looks like this:

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
        google()
    }
}

Then Clean-Rebuild-Run .

first, check with your gradle-wrapper.properties which should be having this

distributionUrl=\
  https\://services.gradle.org/distributions/gradle-4.1-all.zip

and in project-level build.gradle

build script {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

also you need to change according this https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations

and see the topic Migrate dependency configurations for local modules you will get better idea what things need to change in dependencies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM