build.gradle dependency results in compile error - android-studio

After a long time, I have updated my Android Studio environment to the latest versions, but now my project doesn't compile anymore.
The error message displayed says
Could not find com.android.tools.build:aapt2:3.4.2-5326820. Searched
in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/aapt2/3.4.2-5326820/aapt2-3.4.2-5326820.pom
- https://jcenter.bintray.com/com/android/tools/build/aapt2/3.4.2-5326820/aapt2-3.4.2-5326820-windows.jar
Required by:
project :app
The only reference there is to 3.4.2 is in build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
}
but if I remove this, the project doesn't compile either.
Any hint on how I can resolve this?

I had the same problem and solved it by adding google() as a repository under allprojects in the build.gradle file:
allprojects {
repositories {
google()
jcenter()
}
}

Related

Updated my Android Studio from 3.4.2 to 4.0,but unable to sync project due to missing of SDK 29(I have downloaded)

Error:
Could not resolve all files for configuration ':app:androidApis'.
Failed to transform android.jar to match attributes {artifactType=android-mockable-jar,
org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, returnDefaultValues=false}.
Execution failed for MockableJarTransform: C:\Users\DELL\AppData\Local\Android\Sdk\platforms\android-
29\android.jar.
Cannot create mockable android.jar
C:\Users\DELL\AppData\Local\Android\Sdk\platforms\android-29\android.jar (The system cannot find the file specified)
Build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
// 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
}
Distribution Url
https://services.gradle.org/distributions/gradle-6.1.1-all.zip
I have tried installing and Uninstalling SDK 29 and Tools ,but same error exists.
Please Help.

Generate Signed APK gives an error in Android Studio 3.4

Build APK and run application on external device work properly, but When I am trying to generate signed APK I got the error message
Could not find com.android.tools.lint:lint-gradle:26.4.
Here is my Project build.gradle
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
//mavenCentral()
}
}
some of articles suggest to change classpath version but I think 3.4.2 is the latest version of gradle.
By updating my android studio to 3.5, problem was fixed. I don't know the reason. this one was my last chance
You should put google() as the first repo inside buildscript{}, i.e.
buildscript {
repositories {
google() //// <--- here
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
}
}

Android build miss intellij

since today I cannot build my android project because of this error :
> Could not resolve all files for configuration ':classpath'.
> Could not find intellij-core.jar (com.android.tools.external.com-intellij:intellij-core:26.0.1).
Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/external/com-intellij/intellij-core/26.0.1/intellij-core-26.0.1.jar
Android studio 3.2.1
com.android.tools.build:gradle:3.0.1
Do you have any clue ???
Thanks a lot
Vlad
I had the same problem with a cordova-android#7.1.1 project. I read this question Android Studio - Could not find intellij-core.jar and I solved by joining more than one answer.
Premise:
Android Studio 3.2.1
Cordova Android 7.1.1
Cordova Cli 8.1.2
Resolution:
File: platforms/android/build.gradle
...
buildscript {
repositories {
google()
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
...
File: platforms/android/app/build.gradle
...
buildscript {
repositories {
google()
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
google()
maven {
url "https://maven.google.com"
}
jcenter()
}
}
...
File: platforms/android/CordovaLib/build.gradle
...
buildscript {
repositories {
google()
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
}
...
This solution is working to me, I hope I helped you
I have the same issues, and change to classpath 'com.android.tools.build:gradle:3.1.0' solve my issues. You can try it.
This answer is heavily based on the ionic article: https://ionic.zendesk.com/hc/en-us/articles/360005529314
This script can be added to the hooks so no need to fiddle with the platforms code manually.
Create a maven_swap.sh with the following:
#!/bin/bash
#remove jcenter
sed -i.bak '/jcenter()/d' platforms/android/CordovaLib/build.gradle
#append jcenter
sed -i.bak '/maven {/{
N
N
a\
jcenter()
}' platforms/android/CordovaLib/build.gradle
cat platforms/android/CordovaLib/build.gradle
rm platforms/android/CordovaLib/build.gradle.bak
note: sed -i.bak ensures linux & mac compatibility.
Make sure the file is executable chmod +x maven_swap.sh
Add in the config.xml the following:
<platform name="android">
<hook src="maven_swap.sh" type="before_compile" />
...
</platform>

Add maven dependency to Android Studio gradle

Just trying Android Studio & Gradle and I want to add Roboguice to my Project, this is my build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
dependencies {
compile 'org.roboguice:roboguice:2.0'
}
gives me
Gradle 'TestApp' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'compile()'!
I tried to move the line
compile 'org.roboguice:roboguice:2.0'
within the dependencies in buildscript but that also failed.
How is this done correctly?
dependencies {
compile 'org.roboguice:roboguice:2.0'
}
Move this part from build.gradle in root (top level build file) to build.gradle in your module

Errors with gradle on Android Studio 0.4.6

Hello StackOverflow,
I have recently updated my Android Studio to the latest version (0.4.6), and I am encountering weird problems with it. When first creating my project, I got this error:
So I obviously went to my SDK Manager and updated my Build Tools to version 19.0.2. However, I still got this error message. I took a look into my build.gradle file and saw that I am missing the android paragraph, So I changed it from this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
To this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
//Other Configuration
}
allprojects {
repositories {
mavenCentral()
}
}
But now I am getting this error message when trying to build (and the older Build Tools error):
I'm not sure what to do now.. How can I solve this?
As suggested by Scott keep your Root level build.gradle file like this
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Content of this file will be included in each module level build.gradle file at the type of Gradle sync or compilation.
Check all build.gradle files inside your modules. They all should look similar to this
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
//Other Configuration
}
dependencies{
// Your all module dependencies here
}
Undo the changes you made to the top-level build file, and make those changes to the build files in your individual modules. In particular, putting an apply plugin: 'android' statement or android block in your top-level build file in that manner won't work. The error message you're seeing is happening because the build system is trying to build an Android app out of the root directory of your project, but none of the source files for such a project are there.

Resources