Cloning a project in Android Studio causes gradle exception - android-studio

I have ligdx/robovm/gradle/android studio project with core, ios, android and desktop subprojects. I wanted to clone android subproject and create very similar one (I named it android-full). I've copy-pasted android directory and renamed it as well as stuff inside it's (build.gradle, AndroidManifest.xml). In settings.gradle I've added 'android-full' to the list. In build.gradle (root directory) I've copy-pasted project(":android") to project(":android-full"). When I'm trying to sync gradle I'm getting an exception:
Error:exception during working with external system:
Full stacktrace from logs here:
http://pastebin.com/T2XUWtYN
A guy from libgdx forums even created github repo with demo project for me (with 2 android subprojects ofc). Gradle works on it without any problem. Here it is: https://github.com/piotr-j/doubledroid
But when I've copy-pasted source code from core/src and android/android-full (without build.gradle) I've immediately got the same exception. I also compared all gradle files with diff checker and they're almost the same (structure is the same as well as version of gradle, I only have more libs).
I use latest android studio (1.4) and gradle 2.4.
I've tried restarting android studio, doing everything again from scratch, deleting .gradle directory, messing in .idea configs and still the same exception, which isn't very informative.

I don't understand how, but I fixed the problem. I just imported it in Eclipse (with gradle plugin). Project appeared without any problem. Then I realized there were fix small bugs in code, cleaned & builded everything again. Then project worked, I closed it and opened Android Studio again. Then it just worked! Some gradle vs android studio bug I guess.

Related

The specified Gradle distribution 'https://services.gradle.org/distributions/gradle-7.2-bin.zip' does not exist

In Android Studio, I am getting the following error when trying to run my app on an Android device:
The specified Gradle distribution 'https://services.gradle.org/distributions/gradle-7.2-bin.zip' does not exist.
All my Android Studio projects are affected by this and restoring them to older commits does not change anything.
The problems all started by following the advice given here: Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-2.1-all.zip'
I deleted everything in my /.gradle/wrapper/dists/ folder. Now, I get the above error and I do not see how to solve it.
Here is how to reproduce it with Android Studio 2021.1.1 on Windows (but be warned: this might corrupt your projects, too):
Delete everything in /.gradle/wrapper/dists/
Create a new project "Test" in Android Studio (this might take a while, since gradle-7.2-bin.zip will be downloaded in the dists folder)
The project builds and runs without errors
Close Android Studio
Delete everything in /.gradle/wrapper/dists/ again
Open project "Test" in Android Studio
Try to run
Now you should get the above mentioned error.
At this point, /.gradle/wrapper/dists/ is still empty. Now you can do the following:
run gradlew tasks in Terminal in the Project Folder of "Test" (this will take a while, since gradle-7.2-bin.zip will be downloaded in the dists folder again)
run gradlew build (everything should build without errors)
But clicking on "Run" still yields the same error.
I am getting the impression that this is an AndroidStudio / IntelliJ bug.
Can anyone help me with this?
Running Android Studio as Administrator solved the problem for me
It turned out my Android Studio installation was heavily corrupted. Simply, uninstalling it and installing it again also did not help.
I basically had to do everything that was suggested here: How to completely uninstall Android Studio from windows(v10)? and delete everything related to Android Studio. I installed it again and now everything is fine again.
I do not know what the problem was. Maybe the .m2 folder, maybe the Jetbrains folder.
My advice to everyone facing the same issue:
First try around deleting caching folders. If nothing helps, go for the brute force approach and follow the answers (not only the accepted answer) of the above mentioned StackOverflow question.

Android Studio: This file not part of the project, but the project builds successfully

I have a strange problem that suddenly appeared in android studio. I created a new cpp file, and included it in Android.mk. Then I synced the project. However, android studio still complains that the file is not part of the project and that I need to sync, BUT the whole project builds successfully.
Likewise, if I remove one of the other older files from Android.mk that it did not complain about, and resyncs and then tries to build the project, as expected the build fails, but android studio does NOT complain that that file is not part of the project anymore.
So somehow, suddenly the android studio editor is not able to correctly identify which files have been synced and are part of the project, but during compilation everything works as expected.
Does anyone know how to fix this annoying problem? I have tried clean project, invalidate caches/restart as well as updating android studio without luck (AS version 3.4).
I used Build > Refresh Linked C++ Projects menu and it worked.
I had a similar problem. Like yourself, I have tried everything.
Invalidate and Restart: Doesn't work
Manual deleting folders: .gradle .idea .ndkbuild etc. doesn't work
Clean, Rebuild, Link C++ Files: Doesn't work
One thing that kind of helped me was: I changed the NDK version. I compiled, then got a compilation error (didn't matter because it was the wrong version of NDK anyway), then I reverted to the original NDK. This appeared to solve the problem, however, it got back again.
My solution was to reset Android Studio to factory settings. If you are on Linux, you can start by deleting these folders:
rm -rf ~/.android
rm -rf ~/.AndroidStudio3.4
Then you download and run your Android Studio and not import anything from anywhere.
I suspect the problem was caused by one of the plugins I've installed.
It may be a good idea to backup those two folders from time to time and reload them from there if necessary.
EDIT: It seems that my problem persisted after the above solution after adding more .cpp files. After seeing that, I searched where that popup came from. It follows that "This file is not part of project..." popup is pushed from ndk-build. (Class name: NewCppSourceNotificationProvider - StaleCppProjectNotificationPanel). What I tried, and what worked so far; I used Android Studio 3.5 Canary13 with NDK version r19c (Stable version). I hope this helps you.
Problem Environment
Android Studio 3.5 RC 2
gradle-4.10-all
com.android.tools.build:gradle:3.2.1
Solution
Update to:
- gradle-5.5.1-all
- com.android.tools.build:gradle:3.4.2
Steps
From the project root run (note this has to be done first):
./gradlew wrapper --gradle-version 5.5.1 --distribution-type all
In root build.gradle file:
buildscript {
//...
dependencies {
classpath("com.android.tools.build:gradle:3.4.2")
//...
}
}
I have similar problem, it could be the compatibility issue of gradle version and gradle plugin version, because my solution is replacing the old configuration
// build.gradle
classpath 'com.android.tools.build:gradle:3.2.1'
...
// gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
with the following new one by changing gradle version from 4.6 to 4.10.1.
// build.gradle
classpath 'com.android.tools.build:gradle:3.2.1'
...
// gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
After that, Android studio can index and track my new cpp files in project.
fix this by update my 'com.android.tools.build:gradle'
Had the same problem with Android Studio 4.0.1 and the latest gradle at this time (6.1.1?). The problem went away after I exited Android Studio and deleted .gradle and .idea folders in the project main directory, plus deleted .cxx and build directories in the affected module directory. I'm not sure which really helped, but most probably deleting .grade and/or .idea
I fixed with update 'com.android.tools.build:gradle' in the artic fox version 2020.3.1
For those struggling with this for me I made a small change to CMakeLists.txt (I altered the version required). This forced the CMake to regenerate, and all missing files were added. This is quicker than the other options listed here.
This applied to NDK 21, so YMMV!
Invalidate cache and restart and you should be good. However, make sure you checked the Clear file system cache and local history checkbox.

Android Studio “cannot resolve symbol R” but project compiles and runs

Android Studio displays in all java files in red : “cannot resolve symbol R” but the project compiles and runs.
I have tried every solution here:
Android Studio "cannot resolve symbol" but project compiles and works, but with no luck.
I tried to :
invalidate caches and restart android studio
delete .gradle and .idea folders
clean and rebuild the project
install a new version of android studio
mess up with gradle file then undo changes and sync project
One thing that I want to try, but I don't know how to achieve, is to reopen the project from scratch as I was opening it for the first time, but I don't know how to do this.
I also tried answers from here:
Android Studio says "cannot resolve symbol" but project compiles,
but again with no luck.
Android studio version = 3.2.1
dependency versions in gradle project file:
classpath 'com.android.tools.build:gradle:3.4.0-alpha01'
classpath 'com.google.gms:google-services:4.0.0'
For some reason that i do not understand ,
this combination of build versions made the issue :
grade version = 4.10.1
classpath 'com.android.tools.build:gradle:3.4.0-alpha01'
when i switched to these build versions :
grade version = 4.6
classpath 'com.android.tools.build:gradle:3.2.1'
The issue was solved !
File -> Close project
Open an existing Android Studio Project
Open you project
Hope it will work.
sometimes, R file is not generated because of package name on android manifest is not match with package module that you have.
Is any wrong syntax or spelling in your xml?
Check your layout or any xml file.
Android Studio seems to have a caching issue with R.java occasionally. I rarely have a problem with this, but when I do, I actually open R.java (double press shift and type "R.java") or navigate to R.java under "app/build/generated/source" directory, opening the file and checking if the relevant XML id has been created. If it has, it forces Android Studio to now recognise the id's that are not being resolved. It's quick to try, and doesn't require clean and rebuild.
From your programs menu, open android studio. instead of opening your project from the recent files, select to open a project from your computer and then locate the path to your project. When all else fails, sometimes this works.
Also, try commenting out the support libraries from your gradle implementation, sync your project, and after sync fails comment them back in and sync again. (not sure if that's what you tried already when you said you messed with the gradle file)
In my case,
I am using
- Android Studio version 3.3.1 at home
- Android Studio version 3.2.1 at office
When i pulled projects to my office computer that are firstly created at my home computer ,
Android Studio can not resolved R file but runs application with no error. Because projects gradle and Android Studio version are incompatible.
Only thing that you sholud do, change the gradle version in project level gradle file
classpath 'com.android.tools.build:gradle:3.3.1'
to
classpath 'com.android.tools.build:gradle:3.2.1'
I was facing same issue,
first thought the issue might because of some xml file or naming of drawable resources incorrectly. After analysing, this case wasn't applicable to me.
So
Updating Android studio from older version 3.2 to newer version 3.3.2 along with new build tool version from SDK manager resolved this issue
for me.
I've tried invalidate cache and Restart AS with clean rebuild all the options but didn't work for me.
It says cannot resolve symbol, but it can run.
In my case, I just reload the needed *.jar files to the libs folder.
File >> invalidate caches/restart
Rebuild Project
Sync
Run
Works for me!
It looks like the library did not load my "imports" properly the first time.
That's why the import methods cannot be seen in my main_activity.xml.
This happened to me when I was going back and forth between different SDK versions.
Apparently SDK manager copied all the source files but it didn't finish cleanly. As a result I could compile and run my project just fine but IDE didn't recognize the SDK and reported all java symbols unresolved.
None of the above and other solutions in SO didn't work for me, but just uninstalling/reinstalling the specific SDK version did a job.
If you renamed your package (inside java folder), make sure you change your Manifest package name to the same
The only thing that worked for me was,
replacing,
import package_name.R
with
import package_name.*
simply go to project settings : settings.gradel and change the rootProject.name to your current name
rootProject.name = "write the project name here"

Android Studio - Gradle sync error on gradle-diagnostics-X.X.X.jar

I've just updated Android Studio and I can't sync my project anymore.
The event log reports:
Gradle sync failed: /Applications/Android Studio.app/Contents/gradle/gradle-X.X.X/lib/plugins/gradle-diagnostics-X.X.X.jar (No such file or directory)
To solve the Gradle sync error, open gradle-wrapper.properties file and update the Gradle wrapper distribution version from:
distributionUrl=https\://services.gradle.org/distributions/gradle-X.X.X-all.zip
To:
Android Studio 3.4
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Android Studio 2.3 distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
Android Studio 2.2 distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Android Studio 2.1 distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
Android Studio 2.0 distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Android Studio 1.5 distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Android Studio 1.3 distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
You can find the latest Gradle wrapper version visiting:
https://services.gradle.org/distributions/
EDIT:
As a side note, as #SeBsZ suggests,
the official repository of the Android Gradle plugin switched from MavenCentral to jCenter (see Bintray blog post).
Make sure your project build.gradle file contains the new repository and the new classpath:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
This is not strictly related to the question problem, but since we are already migrating to the new IDE preview it's better to make sure everything is in place.
If, like me, you are using an older project then you might still be using the maven repository. Make sure you change the repositories in your top-level build.gradle from maven() to jcenter(). Then make sure you are using the correct dependency as well: classpath 'com.android.tools.build:gradle:1.3.0-beta1' for the new 1.3 preview.
For me helped to set chmod on the .gradle directory to 777. After this whole Android studio started working correctly.
I got the same issue after updating android studio to 3.4
I resolve this updatig gradle-wrapper.properties
I had
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
I leave
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
and with this To solve the Gradle sync error.
This is the weirdest thing ever and I never expected it to work but this:
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
worked and got everything fixed (it was the '\' after https). It does make sense since that is an actual link to a file.
check your .bash_profile file and make sure your GRADLE_HOME points to a valid path, if things were working and you face this issue after android studio update, chances are your gradle got updated too.
Here is the example of my gradle home in .bash_profile:
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.14.1/bin
Had the same problem with a newly set up Android Studio 2.2.2, gradle wrapper 2.14.1. I loaded the project before i installed the needed android-23 library and installed java after Android Studio installation.
Error message in Android Studio 2.2.2:
Error:The specified Gradle distribution
'https://services.gradle.org/distributions/gradle-2.14.1-all.zip' does
not appear to contain a Gradle distribution.
Error message in cmd:
projectfolder> gradlew
Exception in thread "main" java.lang.NullPointerException
at org.gradle.wrapper.BootstrapMainStarter.findLauncherJar(BootstrapMainStarter.java:34)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:25)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
When i used gradle from cmd however it worked
projectfolder> set PATH=%PATH%;C:\AndroidStudio2.0\gradle\gradle-2.14.1\bin\
projectfolder> set GRADLE_HOME=C:\AndroidStudio2.0\gradle\gradle-2.14.1\bin\
projectfolder> cd C:\projectfolder\
projectfolder> gradle
BUILD SUCCESSFUL
In cmd i see that the gradle versions and android sdk version were correct
C:\>set | find "JAVA_HOME"
JAVA_HOME=C:\Java\jdk1.8.0_111\
However in C:\Users\.AndroidStudio2.2\system\log\idea.log it said something else:
2016-11-29 16:04:10,597 [ 107684] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/AndroidStudio2.0/jre
2016-11-29 16:04:10,597 [ 107684] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/AndroidStudio2.0/jre
After messing up Android Studio config files i ended up reinstalling everything in correct order (Java, Android Studio, Project) and it worked.
I got the same issue after updating my android studio to 1.5
Here is my error stack trace.
Error:A problem occurred configuring root project 'Kargo'.
java.io.FileNotFoundException: /home/adiyatmubarak/Documents/android-studio/gradle/gradle-2.4/lib/plugins/gradle-diagnostics-2.4.jar (No such file or directory)
After I checked to the android studio instalation directory within gradle, my gradle was gradle-2.8 I don't know how to setup my android studio path location, but for temporary fix I just rename it to gradle-2.4 and my problem solved.

Imported jar in gradle, compiles, but not recognized by Android Studio (0.2.10)

This is an annoying one.
I have a simple project structure which is based on Gradle, very similar to other projects I have.
The project has these imports:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/jackson-annotations-2.1.0.jar')
compile files('libs/jackson-core-2.1.0.jar')
compile files('libs/jackson-databind-2.1.0.jar')
compile files('libs/zip4j_1.3.1.jar')
compile files('libs/httpclient-4.1.3.jar')
compile files('libs/httpclient-cache-4.1.3.jar')
compile files('libs/httpcore-4.1.4.jar')
compile files('libs/httpmime-4.1.3.jar')
compile project(":grid_lib")
}
Which works well.
The only problem is that the Android Studio does not recognize those classes, so they are all in red and have no intel.
Very annoying!
I've been banging my head against the wall for too long, so I'm trying here now. What do you say guys? Any ideas?
Thanks :-)
Edit
I've answered my own questions, for those who find the same problem.
well, to answer my own question...
Sometimes Android Studio's Gradle goes haywire, and I found a simple fix:
Restart Android Studio
Create a new project (doesn't matter where or name)
Wait for it finish downloading its gradle stuff
Restart android studio
For other gradle problems, an additional step may be required, which is copying the gradle wrapper (gradlew files, and gradle folder, not the .gradle folder) from the newly created project to your own project, and re-import your project.
You can now delete the new project... of course.
Edit:
Gradle's version keep changing.
If you are still having trouble, try this-
Edit your gradle/wrapper/gradle-wrapper.properties file, and update the distribution url's version. Currently it should be 1.8, but it may change in the future. So you can use a "new project" to find out what the version should be. Example: distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
Edit your build.gradle file, and change the minimum version to 0.6.+ - and again it may change in the future. Example for current versions: classpath 'com.android.tools.build:gradle:0.6.+'
Restart your Android Studio and recompile.
I encountered the same problem once I tried to upgrade Crashlytics to Fabric which cost me few hours to solve it.
I tried cleaning the project and rebuilding it from IDE and Terminal, closed Android Studio and opened it again, synced the gradle, checked out to other git branches and so on. Non of them solved the problem!
As a final attempt I closed the project and imported it to Android Studio again and the error was gone!!! I couldn't find any explanation for why it happened but it could be some sort of caching issue on the gradle which was not being cleared in normal ways.
In my case, the problem was that i was using an old version of a jar library, and when updating to a newer version Android Studio was not recognising the classes, but it was compiling anyway. But i got this annoying red font color and underlining.
None of the solutions in this thread worked for me.
The solution for me was adding in the build.gradle the following:
repositories {
flatDir{
dirs 'libs'
}
}
And of course, the common (but these lines come by default):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

Resources