Disappearing R.class - Android Application Development - android

I'm struggling with disappearing R.class due to some problem in styles.xml - it says
Error retrieving parent for item:
No resource found that matches the given name 'Theme.AppCompat.Light'.
Problem appeared while exporting project to another laptop....
styles.xml below.
Thanks in advance.
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

This means you do not have the support library in your build path on your new machine. See the adding support libraries with resources section of the docs for your answer.

First of all I suppose you tried Project -> Clean or to close and re-open eclipse itself. Then you must ensure of adding support libraries as said up.

Lack of R file can be caused by many reasons.
Possible Solutions
Sol 1. Since it is associated with Theme.AppCompat.Light( which is defined in support library) it may be caused by lack support library in your build path(Appcompat).
Sol 2. Check the version of appcompat and make sure you have the latest one.
Sol 3. Just to be sure. Undo latest changes done in any xml files( or replace the xml file from history).
Sol 4. If you have already added support library and the problem still exists then delete android-support-v4.jar from lib folder if present( this is because conflicting support jar files can cause R file errors).
Sol 5. Check Project Build Target.(Project>Properties>Android)
You can also make sure 'Theme.AppCompat.Light' is present in your support library by placing the cursor between the text(Theme.AppCompat.Light) and press control button which should underline the whole text.
I hope it helped..

Related

error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.NoActionBar'

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/colorTextPrimary</item>
<item name="android:textColorSecondary">#color/colorTextSecondary</item>
</style>
This is the styles.xml file. The following code results in this error - i have put all the necessary libraries and jar files and i have also tried changing the syntax little bit and many stuff but I am not able to solve the problem. It is very important. Please help me. Thank you.
I have tried the following :
You need to reference this AppCompat library in your Android project.
Import the library into Eclipse.
Right click on your Android project.
Select properties.
Click 'add...' at the bottom to add a library.
Select the support library
Clean and rebuild your project.
It still doesn't work.
Edit now :
I have installed android sdk 5.0 (API 21) but it still doesn't work. The line with the error is
There were 3 other errors before installing android sdk 5.0 (API 21) in this file (styles.xml) but now they are gone. Please help me to remove the remaining error.
If you are using material in the manifest, you will get this error if your min version isn't API 21

Android development through Eclipse

I try to use the android development tools trough Eclipse Luna.
Exactly I try to use the JBoss for cordova developmet
I have a problem to run the Android emulator. So I tried first to create a clear Android Application project and it have the following error.
What should I do to fix them and run the emulator properly?
styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
ActionBar is found in support library v7. Maybe it's missing.
You can right click in your project -> Properties -> Android
There you should see a library added with a green mark like the following:
If you don't have any library there, you should import the library by going to: File -> Import -> Android -> Existing Android Code Into Workspace
Then look for your library v7 into the sdk folder like the following picture:
Then click finish:
And go back to right click on your project and go to properties to add the library by clicking in the Add... button and selecting the library:
Hope this solves your problem!

AppCompat V7 - Cannot customize material Theme

I added the AppCompat V7 library to add some Material Design elements to the UX of an app that has to support older devices (android:minSdkVersion="16")
I was able to add the Theme.AppCompat.Light theme to my app and even did some customizations of the action bar with #style/Widget.AppCompat.Light.ActionBar.Solid.Inverse. The problem comes when I try to do the simplest changes to the main theme, like changing colors as follow:
<style name="Theme.AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
</style>
I keep getting this error: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'..
I already checked that the build targets for the project and AppCompat are the same, but with no luck.
I think it has something to do with refering to the resources from the library, because when I copy the themes.xml file to my project, it works.
Is that the way I'm supposed to do it? Wasn't the library there to contain all the resources I need so I wouldn't have to copy them manually?
Thanks!
Build targets for your project and AppCompat-v7 need to be both level 21.

In android when i try to run my project it says 'No resource found that matches the given name 'Theme.AppCompat.Light'? [duplicate]

This question already has answers here:
No resource found that matches the given name '#style/Theme.AppCompat.Light'
(4 answers)
Closed 8 years ago.
'No resource found that matches the given name 'Theme.AppCompat.Light'
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
here is the error ->>><style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
-->open android SDK manager,make sure that Android Support Library is installed..
-->After that the AppCompat Can be found at
android-sdk/extras/android/support/v7/appcompat
-->You need to reference this AppCompat in your android project.
-->Import the library to eclipse.
-->Right click on your android project. Goto Properties. goto andorid. Click Add Library and reference the same.
-->Clean and Rebuild your project

Android ActionBarCompat library

I'm having trouble using ActionBarCompat support library which was released yesterday. I have updated support repository and included path to appcompat-v7 repository in build.gradle as Chris Banes pointing out in DevBytes - https://www.youtube.com/watch?v=6TGgYqfJnyc .
dependencies {
compile ('com.android.support:support-v4:18.0.+')
compile ('com.android.support:appcompat-v7:18.0.+')}
Build goes well and I can use classes such as ActionBarActivity from this library but I cannot use styles and any resources so I cannot use following themes - #style/Theme.AppCompat etc. I was thinking that I'll find source files in .../sdk/extras/android/.../"supportrepo" so I would reference it like ActionBarSherlock by gradle but that didn't seems to be the correct answer.
What am I doing wrong? Thank you.
I'm using Android Studio and I have the same res-resolving issue in the my values/styles.xml.
It says it cannot resolve #style/Theme.AppCompat.Light, but at compile-time (gradle) and runtime everything works fine (Android 2.3.3 & 4.3).
I'd like to get rid of the warning that the res cannot be resolved.
How can I tell Android Studio that this res can be found in the appcompat-v7 repo?
(This question was related to a bug in Android Studio that has already been fixed.)
Below you see what I did. I hope this will help. Suggestions appreciated.
The source for the appcompat library can found on github.
Gradle integration:
dependencies {
...
compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
...
}
Style-files:
values/styles.xml:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBar.Solid.Custom</item>
</style>
<style name="ActionBar.Solid.Custom" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_custom</item>
<item name="displayOptions">homeAsUp|showHome|showCustom</item>
</style>
</resources>
values-v14/styles.xml:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 14 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBar.Solid.Custom</item>
</style>
<style name="ActionBar.Solid.Custom" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_custom</item>
<item name="android:displayOptions">homeAsUp|showHome|showCustom</item>
</style>
</resources>
MainActivity (only the extend is mandatory):
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Views.inject(this);
setupNavigationDrawer();
}
}
AndroidManifest.xml (setting android:theme is mandatory):
<activity
android:name="com.example.app.MainActivity"
android:theme="#style/AppTheme"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
There is a known bug (http://code.google.com/p/android/issues/detail?id=56312) where the Android Studio IDE will flag the style as red (that bug is for ActionBarSherlock, but the issue is to do with an aar containing styles and the sources for that aar not being visible to Android Studio).
Specifically, comment #8 (http://code.google.com/p/android/issues/detail?id=56312#c4) shows the observed behaviour, and comment #10 (http://code.google.com/p/android/issues/detail?id=56312#c10) notes that the layout editor is fixed, but the code editor is not.
Thus, the program should build & run fine, just show the style in red when viewed in the XML style editor.
I have not tried Gradle yet so I am not sure but it seems you also need to copy resources into your project.It contains Theme.AppCompat.
I got success in Eclipse by following below steps.
Import android-support-v7-appcompat as a libray project from below path.(you might have saved sdk on different path)
D:\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\extras\android\support\v7
The I just added this library into my project and things worked out of box.
I also added the same 2 lines to my dependencies section in the build.gradle file. Compiling started to work but I got runtime errors. Then I discovered the option Tools > Android > Sync Project with Gradle Files. This seemed to do the trick. (I'm on Android Studio 0.2.9)
In my case, Lastest Studio 0.8.1
Create new project and set Style to AppTheme. then crash.
My solution:
File -> Project Structure -> Dependicies -> + (plus) -> select appcompact, support, ....
And error fixed.
thanks.
Cf https://plus.google.com/113735310430199015092/posts/ef5LyGyMddy
David Van de Ven
Except someone forgot to update the support repository, so anyone
using android studio will have their gradle builds break when trying
to use the new support library.
Roman Nurik
+David Van de Ven we're working on that.

Categories

Resources