Gradle build in Android Studio - android

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).

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.

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"
}
}
}

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.

Related

Failed to resolve: com.android.support:appcompat-v7:27.0.0

So, I built an app using targetSdkVersion 25, but then I realized that it's necessary to be higher than 26. I tried to upgrade it to API 27 and I am getting this error:
Error:(24, 13) Failed to resolve: com.android.support:appcompat-v7:27.0.0
Under this message there are three options:
Install Repository and sync project
Show in File Show in Project
Structure dialog
My build.gradle(Project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.simon.onequoteaday"
minSdkVersion 14 //9
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-ads:11.0.0'
compile 'com.android.support:appcompat-v7:27.1.1'
}
I've also installed all API 27 SDK.
Any possible solutions? Thank you
Edit:
I've already used the solution provided by other threads but they don't solve my problem. I think my problem is different.
replace maven {url "https://maven.google.com"} with google(); the location has changed.
Change
buildtoolsversion '27.0.0'
and dependencies as:
compile 'com.android.support:appcompat-v7:27.0.0'
and stay connected to internet and download whatever repository it asks.
Hope it helps.
Installing the newest Android Studio version solved the problem

Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:support-v4:26.1.0

I'm using Android Studio 3.0.1. I updated Android SDK and Android tools. Also I searched and tried various solution other people tried, but none of them worked.
What should I do?
Top Level build gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app build gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.reminder"
minSdkVersion 14
targetSdkVersion 26
buildToolsVersion "26.0.2"
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner" }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
}
gradle sync screenshot
Put the following lines in gradle.properties file inside your project:
systemProp.http.proxyHost=fodev.org
systemProp.http.proxyPort=8118
systemProp.https.proxyHost=fodev.org
systemProp.https.proxyPort=8118
And also in the following file:
Windows: C:\Users\[username]\.gradle\gradle.properties
Linux: /home/[username]/.gradle/gradle.properties
And finally sync your project again.
Note: The credits goes to the author of the post in this link.

Butterknife gradle error on Android Studio 3.0 due to android-apt plugin

After upgrading to Android Studio 3.0 I had some issues with gradle that I was able to fix checking on the developers website
However, I was not able to find how to fix the issue with the apply plugin: 'android-apt' I have tried several things such as removing it from the project gradle and add it to the app gradle as annotationProcessor 'com.neenbedankt.gradle.plugins:android-apt:1.8' . also removed the apt, etc, etc.
Anyway, Studio is complaining about it. Any help is greatly appreciated. Thanks!
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
jcenter()
google()
maven { url "https://jitpack.io" }
}
ext {
supportLibVersion = '27.0.0'
firebaseLibVersion = '11.4.2'
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
APP GRADLE
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
defaultConfig {
applicationId "xxxxxxxxxxxxxxxxxxxx"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
apply plugin: 'android-apt'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:${supportLibVersion}"
.....
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
Do not use apt plugin, add the dependency like this:
compile "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
Reference
If you are in hurry you can disable that thing.
As per Document
If you are experiencing issues migrating to the new dependency
resolution strategy, you can restore behavior to that of Android
plugin 2.3.0 by setting includeCompileClasspath true. However,
restoring behavior to version 2.3.0 is not recommended.
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
}
And one more thing you have to define flavorDimensions "default" property in buildTypes tag in gradle file.
You can check more about this here.

gradle sync failed when use android.support.library

I want to add android.support to project:
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.myapplication2_gradle26_3.app"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}
and when sync the gralde this error fired
Error:Gradle: Execution failed for task ':app:processDebugManifest'.
Error: [E:\AndroidExamples\MyApplication2-gradle26-3\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\26.0.0-alpha1\AndroidManifest.xml:21]
Invalid instruction 'overrideLibrary', valid instructions are :
REMOVE,REPLACE,STRICT
the project sync successfully when i add appcompat-v7:22.+ but not when want to add appcompat-v7:26.0.0-alpha1
i tried to update gradle but IDE errored 'u cant use this version'
my IDE is IntelliJ 13.1.15
Update the Android Plugin for Gradle.
Change:
classpath 'com.android.tools.build:gradle:0.12.2'
with:
classpath 'com.android.tools.build:gradle:2.3.3'
Also there is no reason to use an alpha version of appcompat. Use the latest stable version of the support libraries:
compile 'com.android.support:appcompat-v7:26.1.0'

Fix plugin version and sync project Error In Android Studio

I am currently opening this file Android Studio 2.1 and the the app is created in Android Studio version 1.5.
Error:(1, 0) Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "abf87974ef3c08e3258fe37c7d5001161385f549"
Fix plugin version and sync project
Open File
I have problem during importing Android Project and it shows error.
After pressing "Fix Plugin" it shows me "Failed To Update".
This is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "app.asharbhutta.com.challanlogin"
minSdkVersion 13
targetSdkVersion 23
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:23.1.1'
classpath 'com.android.tools.build:gradle:2.1.4'
}
This is gradle-wrapper.properties
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
I'm not able to find 'com.android.tools.build:gradle:2.1.4' in Jcenter / Bintray.
Therefore, this error makes sense
Fix plugin version and sync project
As of this post, the latest stable version is 2.1.2
Note: Gradle is completely separate from the Android plugin. The version of gradle-2.14-bin does not always match the plugin number.
This should all be self-explanatory, but to clarify, this is the corrected build.gradle.
Project /build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "app.asharbhutta.com.challanlogin"
minSdkVersion 13
targetSdkVersion 23
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:23.1.1'
// classpath 'com.android.tools.build:gradle:2.1.4' // This shouldn't be here
}
In Build.gradel
in Dependencies classpath end with + sign like i shown
classpath 'com.android.tools.build:gradle:2.2.0+'

Categories

Resources