Gradle project refresh failed after AndroidStudio update - android

I built some android projects with android studio 1.4. Today my computer broke and I reinstalled my operating system . I installed android studio 1.5,but it didn't work with the old projects.I built some new projects and there's no errors.When I open the old projects,there is an error.
Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
I can't find any information about this error,how can I deal with the old projects?
enter image description here

Put this code in your main build.gridle file, may be it trying to use latest gradle and you have used older one in your previous projects.
// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}

I solved this problem.Just changed the information in gradle->wrapper->gradle-wrapper.properties->distributionUrl=https://services.gradle.org/distributions/gradle-2.4-all.zip
to https://services.gradle.org/distributions/gradle-2.8-all.zip.And it works for me.

I have a network restriction at my production environment that causes this issue.
I solved the same problem by downloading a Gradle version manually and use this local deployment directly:
Downloading a proper Gradle version from Gradle site. In my case https://services.gradle.org/distributions/gradle-6.4.1-all.zip
Placing this zip file in a proper disk folder, say /path/to/gradle-6.4.1-all.zip
Editing projRoot > gradle > wrapper > gradle-wrapper.properties, so that
distributionUrl=file:///path/to/gradle-6.4.1-all.zip
A robust and cross-platform setup would be
distributionUrl=gradle-6.4.1-all.zip
This is a relative path to
project_root/android/gradle/wrapper/
So you must copy the Gradle zip ball there.

Related

The project can be opened but can NOT be run now

I download tutorial codes from github, and I unzip it and copy paste it to where my android studio projects are. After I update to SDK 24.0.2, the project can be opened but can NOT be run now.
Pls write a bit more words for clear instructions in steps of what do I do since I am new to android studio. A lot of time I don't understand the terms you experts use.
Can NOT run the project? the green triangle run button is grey so I can NOT run it.
I got these red messages from Event Log
Gradle sync failed: Unsupported method: SyncIssue.getMultiLineMessage().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.
Consult IDE log for more details (Help | Show Log) (41 s 341 ms)
I tried the repo and with only a few changes in two files was able to run the project.
update the root-level build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Updated gradle version to 4.2.1 and added google() to resolve android dependencies.
updated my gradle distribution URL in gradle-wrapper.properties.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Please see if the 6.7.1 is supported on your android studio or not else update to the latest as per your android studio supports, mine is the latest hence 6.7.1
That is it, just by changing these two files I was able to run that app.
Note: I just did bare minimum changes just to make the app run, ideally all the dependency and everything should be up-to-date but changing all those is out of the scope of this question.
I even committed the changes in the forked version of the app code. feel free to try
https://github.com/dk19121991/Court-Counter
Gradle is an app that Android Studio uses to manage loading the libraries of code the project is built with (among other things). But since this project you downloaded is about 5 years old, the version of Gradle in the project may not match up with what Android Studio's Android plugin can support.
Typically, the Gradle app is actually part of the project. You'll see it in the gradle/wrapper directory in the project. You can update the version by editing the file gradle-wrapper.properties, by changing the value in the distributionUrl line. I think you need to make the version at least 6.7.1 if you have a recently updated version of Android Studio, so change that line to look like this:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
The configuration of the project is in the files named build.gradle. The weird thing is, that project seems to have an incorrect duplicate of build.gradle in the root directory of the project (it looks like the one that should go in the app directory). So you can delete the contents of that build.gradle in your root directory and replace it with what would normally be there in a new project. I just copy-pasted this out of a new project. You can paste it into that file:
buildscript {
ext.kotlin_version = "1.5.0"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
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()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And finally, you will want to update the build.gradle file that's in the app directory so it uses the version of Android you already have downloaded (probably SDK 30). So find these relevant lines in the file and change them:
compileSdkVersion 30
buildToolsVersion "30.0.3"
//...
targetSdkVersion 30
After you've made all the above updates, press the "Sync Project with Gradle Files" button near the right end of the toolbar to reload the project from Gradle. It will take a couple minutes because it will have to download the new Gradle version.

Android Studio 3.2 - Could not find com.android.tools.build:aapt2:3.2.0-4818971

I was following a tutorial to develop icon pack for android and when I imported the project I got several errors and it was solved here - Gradle Version 4.6 - Absolute path are not supported when setting an output file name
After solving that error, the following error poped up.
Could not find com.android.tools.build:aapt2:3.2.0-4818971.
Searched in the following locations:
file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom
file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar
file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom
file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar
file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom
file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar
https://jitpack.io/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom
https://jitpack.io/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar
Required by:
project :licensing
I tried to open the URLs and I was able to download JAR (aapt2-3.2.0-4818971-windows.jar) and JSON (aapt2-3.2.0-4818971.pom.json) files from the first 2 URLs. Should I copy these files somewhere? What should I do to solve this error?
Most likely you do not have the Google repository in your project's build.gradle file. Add google() in BOTH locations as shown below:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
I was able to solve the issue by adding google() in both locations:
File -> Project Structure -> Project -> *Now add ", google()" in
Android Plugin Repository
and
Default Library Repository
*
When you upgrade to 4.6 version of gradle. You need following upgrades too. Gradle Plugin Release page.
1. Android Studio 3.+
You need Android Studio version 3.+ to have 4.6 version of gradle. At the time of post latest release was 3.2.1. You can see latest release on this page.
2. Gradle Plugin 3.1.+
You need 3.1.+ gradle plugin for gradle-4.6 support. Check in project level build.gradle.
classpath 'com.android.tools.build:gradle:3.2.1'
At the time of post latest version was 3.2.1. You can see latest release here.
3. Add Google Maven Library
You need to add Google Maven library to project level build.gradle like below code.
buildscript {
repositories {
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
...
}
}
allprojects {
repositories {
google()
...
}
}
see the dependencies of module :licensing and use com.android.tools.build:aapt2:3.2.0 (or even "com.android.tools.build:aapt2:3.2.0:windows") there, which is the final version ...that 4818971 version should ordinary come with an alpha prefix/suffix (the version number seems to be incorrect). maybe adding repository google() might be required, too. ordinary, that dependency should be present; removing that dependency might be another possible option.
For those people who still face exactly the same problem even after adding two google to BOTH positions in relevant gradle file.I would suggest you to check Android Studio -> Preferences -> HTTP Proxy page.
If you find it says some warnings like "...have set JVM proxy to 127.0.0.1".Then you should consider vpn-related issues which depends on your context.
If your desktop is MacOS, then go to Network setting page, advance->proxy tab,uncheck all the checkbox there.
Back to your IDE as following steps: Android Studio->File->Invalidate Caches/Restart.After that,go back to check Android Studio -> Preferences -> HTTP Proxy page again,previous warnings should be gone.Run again.
I solved my issue by upgrading my classpath from
'com.google.gms:google-services:4.0.0
to
'com.google.gms:google-services:4.2.0'
hope this helps

How to hardcode actual path to a maven repository in Gradle, Android?

I have an strange issue. I just pulled our master branch and I am the only developer who get following error message among many Android developers in my company.
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':bookingcore-android:debugCompileClasspath'.
> Could not find play-services-ads-identifier.jar (com.google.android.gms:play-services-ads-identifier:15.0.1).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-ads-identifier/15.0.1/play-services-ads-identifier-15.0.1.jar
we have following in root build.gradle file
repositories {
google()
jcenter()
...
}
and in one of our modules:
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
dependencies {
....
implementation "com.google.android.gms:play-services-ads-identifier:15.0.1"
}
Based on my search, actual maven path to play-services-ads-identifier.jar is https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-identifier/15.0.1. Is there anyway to tell gradle to download play-services-ads-identifier.jar from this link rather than google maven?
Based on my search, actual maven path to play-services-ads-identifier.jar is https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-identifier/15.0.1
No, that is a Web page. Among other things, it contains:
Note: this artifact it located at Google repository (https://maven.google.com/)
On my Android Studio 3.1.4 installation, like your coworkers, I am having no problems with:
implementation "com.google.android.gms:play-services-ads-identifier:15.0.1"
when I have google() listed in allprojects { repositories {} } in the root build.gradle.
For some reason, your Android Studio seems to think that this is a JAR, when it is really an AAR.
Tactically, you can force the issue, by changing the line to:
implementation "com.google.android.gms:play-services-ads-identifier:15.0.1#aar"
However, that is treating a symptom, not whatever the underlying problem is.
If you want to try fixing the underlying problem, try these:
If you have not done so already, do Build > Clean Project, and see if it picks up the AAR (I doubt that this helps, but it's always a good first step)
If that does not help, try File > Invalidate Caches/Restart, and see if it then picks up the AAR
You can try to clear the build cache if you are using Gradle 3.3 or higher, then see if it picks up the AAR
If that does not help, you can try closing Android Studio, renaming ~/.gradle/caches (or the equivalent on Windows) to something else, re-opening Android Studio, and seeing if it then picks up the AAR as it re-downloads all of your dependencies (if this works, you can delete the renamed directory; if it fails, you can always restore the renamed directory)

Missing top-level build.gradle in multi-module project

I'm missing the "Top-Level" project build.gradle script from my project:
I imported it into Android Studio from a very complex Maven/Eclipse project, and it basically made a module ("android") in the top level of the directory, and added all the submodules ("tappurwear", "shared", etc) into that original module's directory.
I know this is a kind of messed up structure, but there's a lot of other build scripts so I can't really just move all the files into a proper separate module.
So now I'm wondering, how do I add a top-level build.gradle script, for the entire project? The usual Android Studio projects I've seen just have one, but it's treating my top-level build script as the "android" module's build script. Can I create a new build.script to be the top-level project script that shares settings with the other modules? Is there a way I can rename the top-level build script that gets used in all other module scripts, in Android Studio or Gradle?
I had the same issue on my multi-module project, this solution worked for me.
Closed all the open projects.
Removed project from recent projects in "Welcome to Android Studio" window.
Now click "Open existing android studio project" & browse to the project repo & select top level build.gradle.
close your project
rename the project directory (in the workspace)
open the project with the new name
wait for gradle sync, build.gradle (project) should be added to the Gradle scripts
close the project
rename the project directory with the original name
reopen the project with its good name
wait gradle sync, the build.gradle should be here again...
// 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.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
It really doesn't matter from my experience, what you need to do is make a build.gradle file, with your favorite .txt writer (make sure it says .gradle). If your root foldere app name is say "Archiver", then you put the gradle file where you see folders like app, .idea, gradle, e.t.c.
One thing you have to keep in mind is that you may need to add a pointer to this gradle if your project can't find it for some reason.
To make sure your project looks good, go to File >> Project Structure >> Module (and every other menu you feel you implemented). If you don't see any red x's then you may be good to go.
Close project.
Remove ".idea\project_name.iml" (name are usually same as project folder).
Remove reference to this file from ".idea\modules.xml".
Open project.
IDEA will re-create this file in projec's root folder instead of ".idea" and project-level "build.gradle" appears. This makes me think that better solution could be just moving this file outside ".idea" and correct reference in ".idea\modules.xml".
You can just add build.gradle for root folder which contains gradle.properties and settings.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:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
The following steps resolved the issue for me:
Close project.
Remove ".idea\project_name.iml" (name are usually same as project folder).
Remove reference to this file from ".idea\modules.xml".
Open project in IDE

Studio failed to download library from gradle repository

I already saw this question, but it is not helping me. First of all, I tried to add google play services in my project using:
dependencies{
compile 'com.google.android.gms:play-services:6.5.87'
}
It was showing me error:
Then I updated my studio to 1.0.1 and gradle to 1.0.0. And then I again synced the project with gradle. And it worked! It showed me another option despite of two options shown in above screenshot. It was "Install the library"(something like that). I clicked it and it popped up a dialog, and I installed the library(it was like downloadind using SDK manager and not like gradle downloads).
Now, I tried to download this library using:
compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
}
And it gives me error:
My android repository is updated:
Also, my internet connection is working fine. I tried to sync project many times, but same error all the time. I am not running gradle in offline mode:
How to fix this? And what is the permanent solution? And why is all this happening?
I found this question: Studio failed to download library from gradle repository which describes the exact same error, and that question had this bit of build script that you need to add to the build file that has the dependency statement in question:
repositories {
maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
When I do this, it works for me.
As to the general question of why this happens (and the better question of why the solution is different for different libraries):
Gradle, the build system that Android Studio uses, has the ability to automatically download library dependencies from the Internet. By and large this is a big boon for developers, because instead of having to manually download archive files, put them in the right place in your project, check them into source control, and repeat the process for new versions, now you just have to add a line of build script and the build system takes care of the housekeeping for you. The major downsides are Internet connectivity woes, which affect different developers to different degrees, and some added confusion about what it means when you get an error.
How does Gradle know where to download dependencies? Most Gradle build scripts contain a block that looks like this:
repositories {
jcenter()
}
or it may be mavenCentral() instead of jcenter(). This tells the build system to look in the JCenter or Maven Central global repositories (and JCenter is in a simplistic way of thinking about it a value-added mirror of MavenCentral); these contain archives of many versions of many, many, many libraries and are very convenient to use.
You can specify other repositories as well. This swipelistview library hasn't been uploaded to Maven Central, so the developer has made a repository for it available via a URL: if you add that URL to your repositories block, it will look for it there.
I was worried about the fact that you're accessing a SNAPSHOT version of the library -- these are supposed to be unpublished by definition. But adding a dependency on the snapshot version of the library in my test project worked for me, and looking around that URL in a web browser reveals that there's only a "1.0-" (trailing dash included) version of the library, so there's some subtletly there I'm missing; if you know more, please edit my answer or comment.
In any event, there are a couple caveats to this explanation. Some libraries aren't on Maven Central or on any Internet-accessible archive (at least they're not officially published by Android), but are instead published as part of the Android SDK download and maintained via the SDK manager. The Android support libraries and Google libraries fall under this category. If you get errors about those not being found, you have to fix it via the SDK manager.
How does the build system know to look in the SDK for those, since you didn't tell it via the repositories block? This behavior is hardcoded into the Android Gradle plugin.
The other caveat is that there's a detail that trips up a lot of people, which is that you actually have two repositories blocks, though with the usual Android Studio setup they're often in different files. One is in a buildscript block, which usually lives in the top-level build.gradle file and looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other often also lives in the top-level build.gradle, but you can augment it with another block in your module's build.gradle file. The top-level one looks like this:
allprojects {
repositories {
jcenter()
}
}
and a module-level one would look like one of the previous examples in this answer. What do all of these mean?
The buildscript block tells Gradle where to find build system plugins. These are plugins that enhance the functionality of the build system itself but don't say anything about your actual project. In Android projects, the Android Gradle plugin is in this category, and unlike the Android/Google libraries, this one does live on Maven Central. The repositories block (in coordination with the dependencies block, which is not the same as the dependencies block for your project, keep reading) in buildscript tells the build system where to go look for these plugins.
The allprojects block in the top-level build file tells the build system to apply the bit of contained script to all build files in the project. In this example, it's telling it to add a repositories block pointing to JCenter to all subprojects. This is a convenience so you don't have to copy/paste it into multiple build files in your modules.
In your modules, you also have a repositories block, which in conjunction with the allprojects thingy, tells the build system where to go to get library dependencies for your project, as was previously discussed.

Categories

Resources