I am a new in Android Development and I am having some issue about the R.java file. And I read some suggestions that in order to generate this file you shouldn't have any error on the XML file. In my case I fave an error in my styles.xml
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
And also this:
ActionBarActivity cannot be resolved to a type
And I read this solution that I need to reference the AppCompat but when I checked on my settings the AppCompat has an error.
I already updated my SDK tools with the latest one
And also can you help me how can I solve the problem in the R.java. What I know is it is auto generated but in my case it doesn't generate even I start a new project.
Can you help me with this? So that I can continue my study. Thanks.
Related
This question already has an answer here:
Migrate resource files to Androidx
(1 answer)
Closed 3 years ago.
I've have recently migrated my app to AndroidX, blindly without knowing the ins and outs. As a result every time I run the project, it gives me a load of errors.
I have updated all my Gradle Dependencies and targetSDK to the most recent version code. I have also added the following to gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
But this has still made no difference.
Some of the following are examples of errors I am getting:
error: package android.support.annotation does not exist
error: package android.support.v7.widget does not exist
error: package RecyclerView does not exist
error: cannot find symbol class FragmentActivity
error: cannot find symbol class CardView
error: cannot find symbol class FragmentPagerAdapter
error: cannot find symbol class DialogFragment
I would just like to know I can get rid of these errors, as it is stopping me from running the project on my mobile device?
Here you can find the full class mapping.
In your case you have to change the imports:
error: package android.support.annotation does not exist
error: package android.support.v7.widget does not exist
Packages:
package androidx.annotation.*;
package androidx.appcompat.widget.*;
Classes:
android.support.v4.app.FragmentActivity androidx.fragment.app.FragmentActivity
android.support.v7.widget.CardView androidx.cardview.widget.CardView
android.support.v4.app.FragmentPagerAdapter androidx.fragment.app.FragmentPagerAdapter
android.support.v7.app.AppCompatDialogFragment androidx.appcompat.app.AppCompatDialogFragment
android.support.v7.widget.RecyclerView androidx.recyclerview.widget.RecyclerView
You seem to have everything set up correctly in your gradle file. The problem is that there are missing packages that have not yet been converted/migrated to AndroidX. Here's a little trick you can do:
Go to your app.gradle file and right-click anywhere.
Select Refactor on the menu that pops up.
In the sub-menu, select Migrate to AndroidX
Sit back and let Android studio migrate all your files.
To learn more, check this out.
I hope this helps. Merry coding!
In the Android Studio menu go to Refactor and select Migrate to AndroidX.
Rest the android studio will automatically do.
Other than this if you still find the error then you will have to manual perform certain task.
In the layout find all the old one and replace it like
android.support.v7.widget.CardView
with
androidx.cardview.widget.CardView
you will find the mapping related information here https://developer.android.com/jetpack/androidx/migrate/class-mappings
just find the old text by using Ctr+F and copy the replacement text
In the app build
implementation 'com.android.support:cardview-v7:28.0.0'
with
implementation 'androidx.cardview:cardview:1.0.0'
you will find mapping related information here https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
I'm Practically a first timer so forgive me if my question sounds too easy for you.
I made a new android project in Eclipse with lower APIs (8 and 10) but I keep getting an error in styles.xml in values and also the R.java file is not created (which is because of the style problem. as I've learned, it gets generated with project->clean after the styles problem is fixed.)
but later on I made a new project with a higher API (4.0.3) at it's all good and everything is generated the way it should.
now I did my research in the following 3 questions here:
Eclipse Errors: styles.xml no resource, java.io.FileNotFoundException, and also R.java not regenerating
Android .R not generating - checked all common causes
R. java file is not generated. How to fix it?
but none mention the problem being related to lower APIs.
thanks in advance for any help you can provide.
This is the line of the error:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
and in console I get this error:
[2016-06-20 19:05:11 - AndroidApp] D:\Utilities\eclipse\Workspace \AndroidApp\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
[2016-06-20 19:05:11 - AndroidApp] D:\Utilities\eclipse\Workspace\AndroidApp\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
[2016-06-20 19:05:11 - AndroidApp] D:\Utilities\eclipse\Workspace\AndroidApp\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
I've imported the project on my workspace (I did't copy it) recently and got 12 errors.
This application build target is android 2.3.3.
(minSdkVersion is "9" and maxSdkVersion is "14")
The problem is I have no idea with those sort of problems.
This application is in google playstore and all i want to do is just editing some codes but
i can't even build this project. I don't know the reason why. I'm not expert on this so please give me a help.
How can i fix this?
Problems
12 errors, 25 warnings, 0 others
Errors (12 items)
error:Error:String types not allowed(at 'configChanges'with value 'orientation|keyboardHidden|screenSize').
error:Error:String types not allowed(at 'configChanges'with value 'orientation|keyboardHidden|screenSize').
NETWORK_TYPE_EHRPD cannot be resolved or is not a field
NETWORK_TYPE_HSPAP cannot be resolved or is not a field
NETWORK_TYPE_LTE cannot be resolved or is not a field
Notification.Builder cannot be resolved to a type
Notification.Builder cannot be resolved to a type
The container 'Android Dependencies' references non existing library'/Users/Downloads/Folder/downloader_library/bin/downloader_library.jar'
The project cannot be built build path errors are resolved
TYPE_BLUETOOTH cannot be resolved or is not a field
Type_ETHERNET cannot be resolved or is not a field
The library is not found:
The container 'Android Dependencies' references non existing library'/Users/Downloads/Folder/downloader_library/bin/downloader_library.jar'
Make sure the path is correct.
Whatever project have you imported, but within it, you missing one external library which is attached with that project, so you must need to include it first,because the reason of your errors are, some classes of that external library is used in your project, I think that is the only reason. Have you added that library or not?
I am trying to compile my android app that I am crating by following the google tutorial at https://developer.android.com/training/index.html
I have run into a problem where I get the error "R cannot be resolved to a variable"
I followed the suggestions from the other threads such as cleaning/rebuiding, removing all import android.R, and reinstalling my Android SDK Build-tools for every version
Here is a copy of the tutorial project with the issue MyFirstApp.zip
I have taken the suggestions found in other threads, but their solutions have been unsuccessful.1 2 3 4 Please help!
Please let me know if there is any other information you need to fix this issue.
I have seen your code there is an error inside main_activity_actions.xml which is inside your menu folder
It does not find #string/action_search which must be present in strings.xml
So put <string name="action_search">Search here</string> inside your strings.xml
and clean and build the project.
I hope the error will be solved.
It usually append when you have an error with your XML file.
Maybe you try to use an XML variable who doesn't exist anymore. It will not give you any error on your XML.
Verify your XML variable on your file 'Value' and which you call from your Java file
I know many others have experienced a similar issue and I found these questions that were very similar to my issue:
Android Support Library v7: Error retrieving parent for item
error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.ActionButton'
The problem is that I tried the different solutions offered in those answers such as changing the target sdk to something like 14 or 15, and also cleaning and rebuilding the project. I am using intelij and I havent been able to make the following errors disappear:
Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.ActionButton'
Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.Light.ActionButton'
are there any other things that I can try to attempt to correct these errors? any suggestions are appreciated
Maybe you are not including the support library to your project.
Also have a look at this question Use AppCompat Library for ActionBar support
Add the support library from your adt location like this :
adt-bundle-windows-x86_64-20130917\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat
to your project and clean the project..It should fix it.
You should ask yourself the following question "Do I want to support older (<4) android versions?"
If you don't want to, you don't have to use AppCompat. If you do want to support older versions, you simply include the Appcombat library.
Right click on your Hierarchy and select import. Browse to the location of your SDK/Extras/Android/Support/V7/Appcompat/ and import that library.
Now mark the project as a library and add the Library to your app. Now, Appcompat can actually be resolved.