android : cannot build project after upgrading Android Studio to 2.3 - android

So, happily updated my Android Studio from stable version 2.2 to canary channel 2.3.
But, unfortunately, it has serious bug. Project is not able to build.
I tried opening my previous projects and also tried creating new sample application, I got same below error:
Gradle 'MyApplication' project refresh failed
Error:A problem occurred configuring project ':app'.
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.3.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.chint.myapplication"
minSdkVersion 16
targetSdkVersion 25
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(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:25.0.0'
testCompile 'junit:junit:4.12'
}
Am I the only one with this issue ?

So, be careful while this dialog appears:
Choose "Remind me later" and NOT "Update"
Stay with the build version you already have.
Incase, you pressed Update, so just rollback your Android Gradle Plugin classpath in build.gradle(project) to below one:
classpath 'com.android.tools.build:gradle:2.2.2'
This worked for me.

You should update your Android Studio gradle manually.
1° Step:
Follow this path and get your gradle version
C:\Users\[USER_NAME]\.gradle\wrapper\dists
Here you will get "gradle-X.X" (X- is version) in my case it was "gradle-3.3-all"
2° Step:
Go to the following link :
https://services.gradle.org/distributions/
Download your respective version zip file and just past it in the last folder with long random name.
C:\Users\[USER_NAME]\.gradle\wrapper\dists\gradle-x.x\55gk2rcmfc6p2dg9u9ohc31212 HERE
Now open the Android studio, I hope this will work.

I fought a similar issue and resolved it with the addition of 2 characters...
And after updating the gradle-wrapper.properties to target 3.2.1 everything was great for me
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip

If you import external libraries apply changes for "allprojects"
// 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.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Related

Android Studio project sync FAILED

I attempted to import a project that Udacity's android course provided, but there were some issues. In the build.grade(app module) I changed compile toimplementation and testCompile to testImplementation. The project synced successfully, but when I executed the project on the emulator it gave me the following errors.
Could not find com.android.tools.build:aapt2:3.3.1-5013011.
Searched in the following locations:
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
- https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
Required by:
project :app
I think the required libraries needed to build cannot be found, but I don't know how to solve this. I googled the problem, but I can't find a solution.
My build.gradle file is this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 23
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'
api 'com.android.support:appcompat-v7:23.3.0'
api 'com.android.support:support-v4:23.3.0'
api 'com.android.support:design:23.3.0'
}
build.grade(project) is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Beginning with Android Studio 3.2, the source for AAPT2 (Android Asset Packaging Tool 2) is Google's Maven repository.
To use AAPT2, make sure that you have a google() dependency in your build.gradle file.
allprojects {
repositories {
google()
jcenter()
}
}
Check the official documentation.
The AAPT2 (Android Asset Packaging Tool) is a build tool that Android Studio and Android Gradle Plugin.
Android Gradle Plugin 3.0.0 and higher enable AAPT2 by default.
With Android Studio 3.2 to use AAPT2, make sure that you have a google() dependency in your build.gradle:
buildscript {
repositories {
google() // here
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
} allprojects {
repositories {
google() // and here
jcenter()
}

Setting up firebase on Android studio

I am trying to setup firebase on my android studio.I am using a 2.2.3 version.So this is my code in app.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.parth.carpool"
minSdkVersion 22
targetSdkVersion 25
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(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-a`enter code here`nnotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.google.firebase:firebase-core:16.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is the error that I am receiving.
Error:(27, 13) Failed to resolve: com.google.firebase:firebase-core:16.0.1
This is my project.gradle file:
// 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.2.3'
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
To correct this error I installed google play services, google repository, SDK platform,SDK platform tools etc. after I saw some of the posts on stackoverflow. Does anybody have a solution?
First you need to upgrade android studio to the newest version:
If you're not using Android Studio 3.1 to develop your app, you will need to upgrade in order to get the correct version checking behavior within the IDE.
https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html
Then you need to use the following top level gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android Studio provides Awesome tool called Firebase Assistant, it handles any thing you need to setup firebase in you'r project
from Tools->Firebase
just pick which product you want and it'll do all the work for you
Make sure you are connected to a good network
Goto >file -> other settings -> Under build, execution, and deployment
-> you will see Gradle. uncheck the checkbox offline work. Then rebuild your project.
buildscript {
repositories {
// add google here
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:4.0.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Did you try on this link
In your root build.gradle file add the repo:
maven { url "https://maven.google.com" }
It depends upon you how you want to setup you can try both explicit way and implicit way of setting up firebase .the easiest one is implicit one which is given in android studio

Gradle Project Sync Failed, Kotlin

I am using a beta Kotlin and Android-Studio channel. After update to the latest version i got some gradle sync error.
Below are the log i copied from Event Log:
Error:Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0-rc-39.
Searched in the following locations:
file:/home/yourpc/Android/android/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.pom
file:/home/yourpc/Android/android/gradle/m2repository/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.jar
https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.pom
https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.jar
https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.pom
https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.0-rc-39/kotlin-gradle-plugin-1.2.0-rc-39.jar
Required by:
project :
below is the build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.0-rc-39'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
below is the app build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.udebest.myapplication"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
postprocessing {
removeUnusedCode false
removeUnusedResources false
obfuscate false
optimizeCode false
proguardFile 'proguard-rules.pro'
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Please, anyone has an idea about this? I don't really know how can I solve this? I could not find any solutions out there.
Change your repositories in buildscript and allprojects into:
{
google()
jcenter()
mavenCentral()
maven {
url 'https://dl.bintray.com/kotlin/kotlin-dev/'
}
}
This works for me.
First, I updated Kotlin plugin thru tool, Kotlin, configure kotlin plugin update.
After, in App directory, in build.Gradle file search:
repositories {
// You need to add the following repository to download the
// new plugin.
google()
}
I add a new repository
maven { url 'C:/Program Files/Android/Android Studio/gradle/m2repository/'}
this is the path thru my local directory where the resources are. After this try again to sync
Change and try
classpath 'com.android.tools.build:gradle:3.1.0-alpha04'
to
classpath 'com.android.tools.build:gradle:3.0.0'
It may be due to the alpha release of gradle.
Use below version of kotlin in build.gradle(Project)
kotlin_version = '1.1.4-3'
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Declare dependency of kotlin in build.gradle(Module) as below
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
check your Kotlin version in build.gradle.
I got the same issue when the version was 1.1.0 which was added by default.
changed to recent version 1.3.21 then it is working fine.
This solution has worked for me for React Native(0.63) after installing react-native-image-picker by Ray Eldath, from above comment
//in android.build.gradle
{
google()
jcenter()
mavenCentral()
maven {
url 'https://dl.bintray.com/kotlin/kotlin-
dev/'
}
}
First, close Android studio, delete the .gradle folder, and then open Android Studio again, probably as an administrator
This will make it sync from the start, and solve the issue.
This issue was resolved for one of my peers.
Uninstall the Kotlin plugin (Preferences > Plugins > Kotlin > Uninstall) and use the version that comes with the IDE .

Gradle build error: Failed to resolve:

I just downloaded Android Studio and created a new project and I'm getting gradle build errors:
Failed to resolve: com.android.support.test.espresso-core:2.2.2
and
Failed to resolve: com.android.support.appcompat-v7:25.3.1
This error was resolved reinstalling the SDK Tools + Repository + API when launching android studio as admin.
I've installed API Level 25 which what I want to build on and have downloaded the SDK Build-Tools. I have also already download the support repository
Here's my app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.jtsalas.mirrorcontrol"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
build.gradle:
// 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.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
From the SDK manager, make sure you have both the Android Support Repository and Google Repository installed and up to date. You should then be able to find the relevant artifacts in sub folders of your /extras/android/m2repository directory
From your error it seems that you are not including espresso libraries. The solution to this is adding espresso core library which is part Android Testing support library which is hosted in the google's Maven repository think this as kind of git repository but for dependencies.
So we tell the gradle build system to look in the Maven repository for dependencies by specifying its URL.
This is done by adding Maven url in the application level build.gradle file under repositories block
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
and in the module level build.gradle file mention the dependencies that you want from the maven repository by mention their name as follows:
dependencies{
//other dependencies go here
//testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
That is the reason for including Maven repository url in the app level build.gradle file, hope this helps.
In project.gradle file, the allprojects root align this way:
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
jitpack is used as the dependency for multiple libraries, if you're not using any sort of library that don't requires it then not include maven line.
Well, I don't know the perfect answer but..... how about comparing with my SDK Tools?
I solved it by uninstalling Android Studios and deleting old versions of Android Studios in my C:\Users[Username] and reinstalled Android Studio as administrator.
It seems like you updated android studio and opening previous project in it.The simplest way is create new project and copy
1. compileSdkVersion 26
2. buildToolsVersion "26.0.1"
3. targetSdkVersion 26
4. compile 'com.android.support:appcompat-v7:26.+'
and paste them in appropriate places in app level build gradle.
it will ask to update to take advantages .. allow it to update.
best luck ... It worked for me.
if your project is Flutter,
clean project [by 'flutter clean' command]
In project.gradle file add [ google() ]
in Android studio: File Menu -> Invalidate...
project.gradle:
allprojects {
repositories {
google()
jcenter()
}
}

Android Build Gradle doesn't complete

I had a problem to run android-studios build gradle, so I tested many solution but unfortunately I couldn't solve my problem:
Now i uninstall my old Android studio and Android-sdk , then I download android studio 1.5.1 that contains default SDK .
I install them and I create an empty project , But it take 30 minutes to build project, I will add dialog window that shown in this period of time .
Finally project created with this error :
Error:(23, 17) Failed to resolve: junit:junit:4.12
Could any one help me ,please ?
build.gradle file content:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.armangar.app.fortest"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
top build.gradle file content:
// 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:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
testCompile is the configuration for unit tests (located in src/test) and androidTestCompile is used for the test api (located in src/androidTest).
The main distinction between the two is that test runs in a regular Java JVM, and androidTest tests run on an Android device (or an emulator).
So, use
testCompile 'junit:junit:4.12'
instead of
androidTestCompile 'junit:junit:4.12'
source: http://tools.android.com/tech-docs/unit-testing-support
I think you have SSL problem.
Try by replacing
jcenter { url 'http://jcenter.bintray.com' }
with
jcenter()
in both repository blocks in build.gradle file and try to build gradle again.
I change jcenter() to mavenCentral() in build.gradle .
So my problem solved
EDIT:
This issue was related to my proxy . So I could not download from jcenter().
If you have a problem same this one, please check your Internet proxy .

Categories

Resources