I will be editing a completely different file than the gradle file... then out of no-where all my objects won't be referencing their proper packages.
The gradle file's format gets messed up then throws this error:
Error:(57, 0) Could not find property 'provided' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#4bd72df3.
Open
File
Running: Android Studio 2.1
This might be happening because of different package names defined. Packages in your project structure and the project ID defined in the gradle file might be different. This difference creates a problem during gradle build. Please paste your gradle file and also a screenshot of your directory structure.
Related
My Gradle build on Android Studio fails with multiple errors such as.
C:\Users\%USER_HOME%\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.0.2.aar\67e074a850e794c5187b156467264a93\res\layout\abc_alert_dialog_material.xml
Error:(26, 22) No resource found that matches the given name (at 'layout' with value '#layout/abc_alert_dialog_title_material').
The project is an exercise code of Udacity Android course. I have no changes of my own. It compiles fine when others try.
Anyone seen the same?
Delete your build cache and then rebuild your project i.e,
Delete the build folder inside your app directory
Rebuild your project and then try again
I was getting these errors because the project name was very long, and the location I was saving the project in, added to it. That apparently caused some files to be missing. Moving the project to another location so that the file names are not crossing the system limit resolved the errors for me.
Thank you all for your help!
I am making an alarm clock. In one of my java file I have to find an drawable file like this: layout.setBackgroundResource(R.drawable.view_touch_selector);
But, it shows error and says can't resolves symbol view_touch_selector. I don't know why it's happening although I have that corresponding view_touch_selector created.
UPDATE (after original android's answer):
Can't resolve symbol 'R' error! The 'R' becomes red in each file.
I think the problem is that view_touch_selector has not been created in the generated R.java file. This is an anomaly (may be common) so you'll have to try one or more of the steps listed below (ordered from easiest/short time to longer). If you execute step 1, then do compile. Then try step 2, then compile, and so on.
From Android Studio, using either File or Menu bar:
Select the res/drawable folder from Project tree and select File -> Synchronize.
Menu -> Build -> Rebuild Project
Menu -> Build -> Clean Project, then build it.
File -> Invalidate Caches / Restart
Menu Tools -> Android -> Sync Project with Gradle Files
The idea is to make the Studio recompile your xml files correctly; Eclipse has a similar problem.
Finally, if all else fails, rename your package, forcing all the project files to be evaluated. Warning, renaming package is not easy.
I never had to do this for fixing this kind of problem.
EDIT: R.java file is at few places. The directories listed here is generated by Android Studio. R.java is at
[project directory]\Application\build\generated\source\r\debug\com\example\android[package
name]
There are intermediate files generated by compiler including view_touch_selector.xml:
[project directory]\Application\build\intermediates\res\debug\drawable
Another file to check, though this is rarely a problem I think, is
workspace.xml. When you select File -> Synch, workspace.xml is updated. File is at [project directory].idea. Again this is using
Android Studio.
In workspace.xml, it should include your xml files like:
layout
url="file://$PROJECT_DIR$/Application/src/main/res/layout/view_touch_selector.xml">
Between R.java and workspace.xml, they should be updated to the latest
date/time. And if you don't see the R.java file, then that's a major
problem related to directories. You may have to create a new project.
Good luck on this one, Tommy Kwee
I've searched all over Google, stackoverflow and other android programming websites, many have suggestions for people who have misplaced files from one folder to another and so forth.. But none that illustrate the problem I'm facing.
It's not a corrupt file as in the case here as I tried this with no success.
The error I'm facing is similar though:
[debug] C:\Users\Name\AppData\Local\Temp\android_manifest_copy6264790980678653632tmp\AndroidManifest.xml:11: error: Error: No resource found that matches the given name (at 'icon' with value '#drawable/ic_launcher').
Similarly, this is happening with an #string element, #style element and another #string, examples below:
'#string/app_name'
'#style/AppTheme'
'#string/app_name'
One thing that I have noticed, and coming from the world of Eclipse, I cannot explain this behavior in Android Studio.. In my 'main' project folder, everything exists and builds correctly for debugging. It seems that Android Studio is trying to build off of a 'debug' folder, which will not build when running 'Build' > 'Rebuild Project'.
Does anyone know where I can place these missing files to get the project to build? Or is this some other problem?
Alright, so after fussing with the rebuild for hours trying different methods (renaming particular files [i.e. those with the problems], rebuilding the app after renaming folders inside the build folder, etc) I finally decided that I would go to the source of the problem and see if it worked like other IDE's. Indeed it did, this is how I performed the fix:
Find the location of the problem - For me, all four of the errors I had were inside the 'build' folder of the project.
Close any open instances of the project
While the project is closed, rename this folder from windows explorer (or other if youre using a different OS) (i.e. If the folders name is "build", rename it to "build.old")
Open the project once more
Go to Build > Rebuild Project
You should not have any issues doing this, like I did.
Specifications:
IDE Platform: Android Studio
IDE Version: Android Studio (I/O Preview) 0.2.2
JRE: 1.7.0_25
My problem is about #drawable/img_1, the pic is JPEG format, while it's extension name is png, I force to rename it jpg extension. Then it builds successfully.
If anyone is using Gradle and sees this it's good to remind about the convention directory structure.
For Gradle you have to put your resources in src/main/res. I migrated a project to Gradle and got the said error when I hadn't moved the res/ directory from the old structure.
I started a new project on Android Studio with "Create Activity" checked and then selected "Balnk Activity" with navigation type "Scroolable Tabs + Swipe".
Then I tried to modify the generated "fragment_main_dummy.xml" layout to set an id to the root Relative Layout.
When I try to run the project I get the following compile error:
...\Test1\build\res\all\debug\layout\fragment_main_dummy.xml
Gradle: String types not allowed (at 'id' with value 'test').
Even if I reset the changes the error persists.
Only by manually editing the mentioned file can the problem be resolved.
So the questions are:
Why are all the res files copyed to the build\res\all\debug folder?
Why aren't these files updated when I modify the actual file in the src folder?
Simply add in the string id "#+id/" in your example "#+id/test"
Regards
This is how Intellij manages resources, it helps with id lookups etc I don't know the specifics, but it is not AndroidStudio but IntelliJ as a whole that works this way with the R file (might help you google it).
The file won't be modified as these are build files, so will be updated when you recompile the project. (i.e. when you run / deploy to a device / build an APK).
I thought IntelliJ auto built projects, so maybe you have turned this off? You can test this with File Menu: Build > Rebuild Project
It seams that I missing the R file, this is a common error and usually I have solved by cleaning the projects, using android tools fix project properties and restarting eclipse.
Now I have installed the new android developer tools eclipse and after importing the project I have this error in eclipse:
Errors occurred during the build.
Errors running builder 'Android Pre Compiler' on project 'MyProject'.
java.lang.NullPointerException
and the R file is not generated so it is missing.
The project is a library project. Thanks
Sometimes if you have errors in an XML file, it will stop the project from building correctly and the resources (project.R) file won't be created properly. You will also need to make sure that you are importing your resource file and not the one from android.R
If you've changed the project build target or minSdkVersion, you might have XML nodes in one of your layout files that isn't supported by the SDK you are using which will stop it from building. That's also worth checking
Go to Project and hit Clean. This should regenerate your R.java file.
Also get rid of any import android.R.* statements and then do the clean up as mentioned.
Otherwise, XML resource under layout may not having the correct naming convention or might be having some capital letters.
Try changing them to lowercase and make sure your layout.xml files don't contains errors.
Clean the project because the project may have trouble finding the name of a resources, it really sucks that i constantly have this problem when adding new image..