Following a tutorial, I have a styles.xml file with the following code:
<style name="ActionBar.Solid.Sunshine"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
Android Studio gives me the error that Widget.Appcompat.Light and Widget.Appcompat cannot be resolved, although it still works at build time. I am a beginner and am quite at lost as to what caused this error. Any pointers?
On another related note, where do I find the list of default resources I can use, such as the Widget given to me above?
Thanks!
Related
I am trying to migrate an Android Studio 3.0 project to Android Studio 3.1.1, which enables the Android gradle plugin 3.1.1 and the new AAPT2 resource processor. I think my problems stems for either of these.
Basically, when I try to gradle sync my project, the error I get is
Users/user/src/app/app-1/src/main/res/values/styles.xml:599:5-608:13:
AAPT: error: :item>.
I have no idea what the error could be based on this error message alone. Googling around for it didn't seem to find anything either. The line this error message points to is nothing special, just a style declaration:
<style name=“AppEditText" parent="BigEditText">
<item name="android:gravity">left</item>
<item name="android:textCursorDrawable">#drawable/drawable</item>
<item name="android:background">#android:color/transparent</item>
…
</style>
Based on the error position and knowing that AAPT2 is now on (it was off previously), I am concluding that the error has something to do with resources, but I have no idea what's wrong.
My project consists of two apps and a commons module both of these apps depend on. The commons module implements some UI components also. Not sure if this is relevant or not.
How would I debug this further?
Update: When I looked at the merged values.xml, as processed by AAPT2, I can see the resulting values.xml contains something strange.
<ns3:item name="layout_columnWeight">1</ns3:item>
<ns3:item name="layout_rowWeight">1</ns3:item>
It looks like the error is from these lines. But how would they have ended up there? Who would add the ns3 namespace and why?
Ok - I finally found out the reason for this.
As a hint for anyone else struggling with these kinds of issues, you should go to the console and do a gradle build with the --info flag and it will tell you in which file the error is happening in while it is processing the resources. This is how I managed to actually see where the error was as the issue was in one of the merged resources files that the developer normally never sees.
The issue was that in some of our XML resources files, the namespace that was specified was support and/or an namespace auto-res line was specified for an element and now caused issues with AAPT2. I don't know why it had worked before, but this was now causing issues with AAPT2. Removing those namespace declarations solves the issue.
I'm trying to use the CoordinatorLayout in my Xamarin.Android app. I've been using a custom theme with Theme.Material.Light as its parent, which worked fine before I added the CoordinatorLayout. When I add it, I get an error telling me I have to use a Theme.AppCompat theme, but as soon as I do the app fails to build and gives me the following error:
/{project directory}/Resources/values/Styles.xml(0,0):
Error APT0000: Error retrieving parent for item:
No resource found that matches the given name
'#android:style/Theme.AppCompat'. (APT0000) (TnpApp.Android)
This answer suggests installing the major version of the support library that matches the Android SDK I'm using. I've tried this (I think I did everything correctly), but it doesn't help.
Does anyone have any ideas?
I'm using Xamarin Studio on Mac.
UPDATE 1
I tried the following code in MainActivity.cs in a clean Xamarin.Android project, and build fails with the same error.
namespace ThemeTest
{
[Activity(Label = "ThemeTest", MainLauncher = true, Icon = "#mipmap/icon", Theme = "#android:style/Theme.AppCompat.Light")]
public class MainActivity : Activity
{
// ...
}
}
UPDATE 2
I removed all the folders from /user/.local/share/Xamarin except for Mono for Android and zips as suggested in this answer. I closed Xamarin Studio and reopened it. I tried to deploy the app, and Xamarin reinstalled all the packages but the build failed with the original error.
I was able to fix this problem by simply removing #android:style/ from the style element's parent tag in my Styles.xml file. So what looked like this...
<style name="MyCustomTheme" parent="#android:style/Theme.AppCompat">
Now looks like this...
<style name="MyCustomTheme" parent="Theme.AppCompat">
I'm shocked the solution is this simple, but it works. :) I got the idea from this code.
I'm developing in Visual Studio 2015/Xamarin and saw this same problem. While I still don't understand the cause or the fix for this problem, this thread did point me in the right direction which seems to have more to do with resaving styles.xml (for my development environment) than anything else.
My styles.xml did not have #android:style/ and I still had the error mentioned above. As described in another proposed solution, I added
<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />
before <style name="MyCustomTheme" parent="Theme.AppCompat">, saved styles.xml and rebuilt my project without errors. I then removed
<style name="MyCustomTheme.Base" parent="Theme.AppCompat" />,
resaved styles.xml and rebuilt with no errors. Visually, my styles.xml is unchanged, but the error is gone.
If you recently installed a google play service related package (firebase for example , but there are many others) , it is possible that this installation messed up with your CSproj and your package.json files (look at your version control history to see if these files were changed), and modified your target api version : Going from target Api 25 to Target 26 for exemple etc.
If this is the case , you should adresse this problem one of two ways :
make sure you download the sdk version that you are now targeting , to do this , go to TOOLS > SDK manager.
or revert back to your old target , by discarding the change the package made to you csproj and package.json files and clean and rebuild.
I'm trying to make an Android app through Xamarin. I work on Windows 10 with VS2015.
I have to implement a side bar menu. After some research I found a solution to do it : use a DrawerLayout and others tools. That's why I use Theme.AppCompat in my application.
But when I'm trying to make a style which herits from Theme.Appcompat.light.NoActionBar, I got compile issue. The message is :
Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.NoActionBar'.
I've added Xamarin.Android.Support.v4 and Xamarin.Android.Support.v7.AppCompat references to my project as bellow :
Project References
Edit: I also tried to add them by xamarin Component and nuget package manager.
But nothing compile.
Here is the code which produce this error:
<resources>
<style name="DailyCoin.HomeTheme" parent="#android:style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#219653</item>
<item name="drawerArrowStyle">#style/MyDrawerArrowStyle</item>
</style>
<style name="MyDrawerArrowStyle" parent="#android:style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">#F5F5F5</item>
<item name="spinBars">true</item>
</style>
</resources>
minSdkVersion is 17 and compile using version is 23
Ok, I found the solution.
My problem was that xamarin was corrupted and the component adding module had some troubles when i added components. So i removed all references/components i've added to my projet, reinstalled xamarin.
Just for people impatient like me:
Then i had a new issue : "Unzipping failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r28.zip" because when generated the solution, it took a lot of time and i stoped this.
The solution was to delete all zips in "%localappdata%/xamarin/zips" and wait for the generation.
Thank for your help !
Julien
Did you try this?
parent="Theme.AppCompat.Light.NoActionBar"
Check this out (its working for me): Navigation Drawer using material design
Leave out #android:style/ so just:
parent="Theme.AppCompat.Light.NoActionBar"
I recently updated Android Studio to version 1.2 and my AppCompat library to v22.0.0, SDK-Build-Tools version to 22.0.1. My target and compile sdk-version is 22 and my 'min-sdk-version' is 16.
The problem I am having is that in the xml-layout preview, I am getting an error namely: "Rendering Problems, the following classes cannot be found: android.support.v7.widget.Toolbar". I did some surfing on the internet and tried the already provided solutions. They are as follows:
Changing my (xml) preview to show android version target 21 or Android 5.0.1, 19, and 17
Changing my styles theme to Holo.NoActionBar and other themes as well.
Changing my minSdkVersion to 21 (above 20 basically)
Restarted Android Studio... Twice
Built the project about 5 times.
However, the problem still remains and I'm out of ideas. Could really use some help here. Thanks...
Also: The classes import just fine in my java file. It's just the preview.
EDIT: The preview works fine when I use android.widget.Toolbar. And my DrawerLayout doesn't work. I'm guessing there's something wrong with rendering the widgets from the support libraries?
I had a similar problem and you may want to try to change the app theme in the style.xml to an appcompat app theme for example with mine I changed it to something like this.
<style name="AppTheme" parent="#style/Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<!-- Customize your theme here. -->
</style>
and then go to the Android Manifests file
<application
android:theme="#style/whatever_you_named_your_app_theme">
In the Android Manifests file you write whatever you wrote in the styles.xml under <style name=""
There is no need to lower your apps targetSDK.
Give me feedback if it worked for you
I wiped out my entire project and started all over again. That seemed to solve the problem. I'm guessing changing my configurations in between is what caused the mess. Thank goodness the project was just for recreation.
Since yesterday everytime I open my layout Editor in Eclipse for the Android UI I get the following exception:
Unhandled event loop exception
java.lang.StackOverflowError
at com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.isTheme(Unknown Source)
at
com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.isTheme(Unknown Source)
at...
the last part goes on and on as expected if an Stackoverflow Exception occurs.
Anybody else experiencing this and found a solution?
I'm working with the latests android sdk on Mac OS X with Eclipse 3.5.2
I just installed the Carbon Version of eclipse and I get this error even in this fresh copy of eclipse.
Very strange that I'm the only one experiencing this error. Maybe it is not an Eclipse problem but an problem of my project setup...
The same thing happened to me, and I had to dig a lot before I found a solution. In my styles.xml I had an entry where the name and parent attributes were identical:
<style name="MyHeader" parent="MyHeader">
<item name="android:background">#drawable/header_background</item>
</style>
By removing the parent attribute the layout editor finally worked again:
<style name="MyHeader">
<item name="android:background">#drawable/header_background</item>
</style>
I have not had that particular error, but I have had various project corruption problems related to resources. Sometimes cleaning the project and rebuilding fixes it. Sometimes I have had to revert some project files in subversion. Sometimes just relaunching eclipse fixes things. There is also a Fix Project Properties item in the Android Tools of the context menu that has helped once or twice.