I've just installed the latest Android Studio on to a new PC, and tried importing an existing project from my Git repo. However I'm getting the following error:
Error:(91, 0) Could not find method android() for arguments
[build_5rpi8n4wxkti5snnxm1rtlcug$_run_closure7#4154e46b]
on root project 'my_project' of type org.gradle.api.Project.
I've tried updating the module settings to use the latest Gradle version, but that didn't help. Any ideas on what that error means or where to look? I guess the org.gradle.api.Project class is missing an android method, meaning it's the wrong version or something?
Finally fixed this myself! It turns out that Android Studio had added a section to the main build.gradle file that shouldn't be there...
At the bottom of the file was:
android {
/** couple of lines **/
}
Deleting that entire block has fixed my build. I'll leave the question up here, maybe it helps someone else having the same problem.
Related
I was working in an android project and everything is ok, but when I try to open the project now, I got the some import errors. Take a look in the image below:
The code still compiles and I was able to run it in the Android emulator, but I can't use the IDE auto complete because of this error.
How can I fix that?
EDIT: the problem appears to be related to the Android AppCompat implementation in this line below
implementation 'androidx.appcompat:appcompat:1.0.0'
I try to change it to
implementation 'androidx.appcompat:appcompat:1.5.1'
But it generate some conflicts with another plugins.
The I return the implementation to the old value, but now when I try to put the version 1.5.1, it generates the following error:
Could not resolve androidx.appcompat:appcompat:1.5.0.
Required by:
project :app
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Not sure if this would help but, I usually do any of the steps below when I encounter that kind of Android Studio issue.
clean/rebuild project
invalidate cache~restart
delete .idea folder inside the root project folder, and re-import or re-open project
delete .idea and .gradle folders inside the root project folder and re-import or re-open project
Afaik, deleting the generated folders is safe, it will just re-run all IDE and gradle configurations from the start.
I am really not sure about this problem, but i think it's IDE error.
you can Clean Project and then Rebuild project.
you will find it in Build tab. or you restarting Android Studio might solve your problem.
last option : you have to remove every dependency then sync after paste every dependency again and sync. You must need internet connection do this step.
I hope this will solve your error.
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 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"
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'])
}
I have found a sample from the Internet (https://github.com/manishkpr/Android-AIDL-Example) and ran on Android Studio and it worked fine.
But now when I am trying to recreate the project, the Android Studio fails to recognize the
.aidl file no matter where I place it.
Can anybody tell me what is the right location to place .aidl files in Android Studio?
p.s. I have added the below code to build.gradle and place the .aidl file in the java directory, but failed to get it work.
sourceSets {
main {
aidl.srcDirs = ['src/main/java']
}
The below link solved my issue.
https://code.google.com/p/android/issues/detail?id=56160
In my case Clean and Rebuild project solved my problem.
Hope this helpful.
The default Android project sourceSet has a definition that looks for .aidl files under "src/main/aidl". Moving my aidl files there solved the problem.
https://code.google.com/p/android/issues/detail?id=56328
AIDL files need to be generated, that's why sometimes when you need to declare a class that is located in an AIDL file, you first have to build these AIDL files before Android Studio can resolve their content.
run
./gradlew assembleDebug
or
gradle assemble
You can also run the task (assemble) under gradle -> build -> assemble