Situation:
I'm currently building a new version of my app for Android L and am also in the process of Chromecast integration.
The app works fine, as long as I extend Theme.Material with my custom style, but doesn't show the Cast button.
Problem:
As soon as I change to Theme.AppCompat, it gives me the error:
Error:Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.DarkActionBar'.
and the same goes for the the Holo Theme as well.
Here's my build.gradle (The libs folder is empty btw.):
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.myapp.myapp"
minSdkVersion 'android-L'
targetSdkVersion 'android-L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:mediarouter-v7:+'
compile 'com.google.android.gms:play-services:+'
}
Here is the relevant part of the values/styles.xml:
<style name="SK" parent="android:Theme.AppCompat.Light.DarkActionBar">
used to work with Theme.Holo.Light.DarkActionBar
and the values-v21/styles.xml:
<style name="SK" parent="#android:style/Theme.AppCompat.Light.DarkActionBar">
used to wirk with Theme.Material.Light.DarkActionBar
I already cleaned and rebuild the project, but it always goes back to showing me errors about a missing parent.
As far as I could gather from similar questions, all relevant libraries are included and all use the newest version available.
I also tried manually adding the libraries to the libs/ folder with no success.
My SDK manager shows that everything is installed and up to date.
What am I missing here?
Thanks in advance for your time.
Solution:
It was actually rather simple. I referred to Theme.AppCompat with the android namespace, but should have left it out, so, instead of
#android:style/Theme.AppCompat
it should be
#style/Theme.AppCompat
This did show another error initially, about "Theme" not being found, but it compiled non the less.
Related
Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here
I'm currently developing an app in Android Studio and have been for several weeks now. I am wanting SDK 21, not 23! SDK 21 has been working for the past few weeks with no problems at all
This morning, I have retuned to my PC to carry on with my programming, went to run the application and these errors appeared:
Error:(3) Error retrieving parent for item: No resource found that
matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(18) Error retrieving parent for item: No resource found that matches the
given name 'android:Widget.Material.Button.Colored'.
Between the app working last night and trying to run the app this morning - nothing has changed. I haven't even closed down android studio. I left my PC on sleep.
I have searched stack overflow and noticed that these errors have occurred for others too. I have tried the answers that have been given to others such as checking the project structure, dependencies, gradle file etc. I have also tried the standard clean and build
This is my Gradle file:
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.example.package"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.1.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:21.0.3'
}
Apologies for the images being links, I'm new to SO so can't embed them to a post yet.
It's completely possible that I am missing something obvious but I have been trying to solve this problem for the past few hours and I'm not getting anywhere.
Any help would be greatly appreciated!
Stand Alone SDK Manager Screen Shot
Dependencies
When you added
compile 'com.google.android.gms:play-services:8.4.0'
This dependency requires the 23.0.0 version of the support-v4 library (FWIW, 8.3 and 8.1 require 22.2.0, hence you are compiling with the API 23 versions of the Support Library.
Keep in mind though, the best practice, as described in the Picking your compileSdkVersion, targetSdkVersion, and minSdkVersion is to always compile with the latest SDK:
It should be emphasized that changing your compileSdkVersion does not change runtime behavior. While new compiler warnings/errors may be present when changing your compileSdkVersion, your compileSdkVersion is not included in your APK: it is purely used at compile time. (You should really fix those warnings though — they were added for a reason!)
Therefore it is strongly recommended that you always compile with the latest SDK. You’ll get all the benefits of new compilation checks on existing code, avoid newly deprecated APIs, and be ready to use new APIs.
Therefore the easiest solution is to change your compileSdkVersion to API 23, while leaving your targetSdkVersion (what controls runtime behavior and use of things like runtime permissions) at whatever level you currently have.
try changing
compile 'com.android.support:support-v4:21.0.3'
to
compile 'com.android.support:support-v4:21.1.0'
I am using android studio and when i try to create a new project i found that the manifest file always contains android:name=".MainActivity" highlighted
with red as well as AppCompatActivity, onCreate and setContentView in the following code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Please let me know how solve it
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.com.myapplication"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
style:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">//cant
resolve symbol Theme+cant resolve symbol AppCompat
</style>
Try sync project with build.gradle.
Do you set right sdk path.
This usually happens when you need to upgrade Android Studio. Please go to
-Tools/Android/SDK Manager, 'Launch Standalone SDK Manager' (at the bottom) and install what it has pre-selected.
Sometimes when you have errors it will pop up in the top right of Android Studio presenting you with a 'Fix' button as well, try re-starting Android Studio and looking out for this option.
If the above suggestions don't work let me know and I'll look further into it.
EDIT: You have not included the support library dependency. This is why Android Studio cannot find AppCompat etc. Please go to your app level build.gradle file and include this line under 'dependencies' and re-sync your project (as it will ask you to do).
compile 'com.android.support:appcompat-v7:23.1.1'
Check if you are using the right versions for these lines. You are possibly using an older version of Build Tools or AppCompat library in your IDE. Maybe Android Studio is not updating the versions in your manifest file when you create a new project.
buildToolsVersion "23.0.2"<--- This line
compile 'com.android.support:appcompat-v7:23.0.1'<--- This line
After installing the updated version of both of these lines, sync project.
I am using Android Studio 1.2.2 to develop an Android Application. In my build.gradle file, I have defined the compileSdkVersion to 21 since the beginning of the work. Now I wanted to change that to 19, since this software actually will never be installed on an Android device, that runs a higher version than Android 4.4
When I try to change this value to 19, the project does not compile anymore.
After the change of the version value I have:
synced the project
cleaned the project
rebuild the project (tried)
But the following error occurs:
In the file /projectpath/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/res/values-v21/values-v21.xml it marks 103 errors, saying "cannot resolve symbol".
values-v21.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- From: file:/usr/local/google/buildbot/repo_clients/https___googleplex-android.googlesource.com_a_platform_manifest.git/lmp-mr1-supportlib-release/frameworks/support/v7/appcompat/res/values-v21/styles_base_text.xml -->
<eat-comment/>
<style name="Base.TextAppearance.AppCompat" parent="android:TextAppearance.Material"/>
<style name="Base.TextAppearance.AppCompat.Body1" parent="android:TextAppearance.Material.Body1"/>
<style name="Base.TextAppearance.AppCompat.Body2" parent="android:TextAppearance.Material.Body2"/>
<style name="Base.TextAppearance.AppCompat.Button" parent="android:TextAppearance.Material.Button"/>
....
cannot resovle symbol android:TextAppearance.Material
cannot resovle symbol android:TextAppearance.Material.Body1
cannot resovle symbol android:TextAppearance.Material.Body2
cannot resovle symbol android:TextAppearance.Material.Button
and so on...
What is causing this error? What can I do to make it compile again?
When I change back the compileSdkVersion to 21, everything works normal again.
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '23.0.0 rc3'
defaultConfig {
applicationId 'com.appname.id'
minSdkVersion 17
targetSdkVersion 19
versionCode 1
versionName "0.0.2 Alpha"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
to use appcompat-v7:22.2.0 you have to compile against API 21. There's no harm in doing it, even if it will never run on devices running 21.
You can try some older version of the app compat, but then you will be missing in "cool new features" and bug fixes from the latest app compat.
If this might help someone, after MANY trials and errors, I found that I was targeting the wrong SDK version (an older one) in the build.gradle file corresponding to "library". To change this you can do it by hand or go to the Module Settings Menu (right click on your project folder -> Open Module Settings. Then in "library" - Properties you can change the Compile Sdk and the Build Tools Versions
make sure you have installed API 19 in sdk manager
I'm trying to use the new CardView from Android L. I updated everything in the SDK manager, but I keep getting the following error:
Failure [INSTALL_FAILED_OLDER_SDK]
This is my build.gradle file:
apply plugin: 'android'
android {
compileSdkVersion 'android-L'
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "www.thomascbeerten.com.nieuwetests"
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// Support Libraries
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.android.support:gridlayout-v7:19.1.0'
compile 'com.android.support:mediarouter-v7:19.1.0'
// compile 'com.android.support:support-v13:19.1.0'
compile 'com.android.support:recyclerview-v7:+'
}
Recently there was a post here regarding the L SDK's incompatibility
with prior versions of Android. I've been digging in AOSP repositories
for quite a few hours now, and determined that the tools behave this
way because they are designed to treat preview platforms differently.
If you compile against a preview SDK (android-L), the build tools will
lock minSdkVersion and targetSdkVersion to that same API level. This
results in the produced application being unable to be installed on
devices running older releases of Android, even if your application
isn't doing anything specific to L. To make matters worse, the new
support libs (CardView, RecyclerView, Palette, etc.) are also locked
into the L API level, even though--according to their repository
names--they should work on API level 7 just fine (and they do!).
See my Reddit post about this here, with a workaround.
Once you have the above issues resolved as mentioned by Eddie. You might also run into another error;;
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.
This will be present in your styles.xml . The quick fix is to replace it with the following below:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--<style name="AppTheme" parent="android:Theme.Material.Light">-->
<style name="AppTheme" parent="android:Theme.Holo.Light">
</style>
Change
android {
compileSdkVersion 'android-L'
buildToolsVersion '20.0.0'
to
android {
compileSdkVersion 21
buildToolsVersion '21.0.2'
Note android-L is in single quotes but 21 isn't. 21 is an integer and not a string.
When you compile with L it actually makes a change during compilation setting your minsdkversion to L. If you want to use RecyclerView or CardView I would recommend checking out RecyclerViewLib. RecyclerView and CardView have been moving into this library so that there is no min version L problem. The author also explained in his blog post how all L related code was removed to make it safe to use.
To add RecyclerViewLb to your project just add the following line to your dependencies in your build.gradle file:
compile 'com.twotoasters.RecyclerViewLib:library:1.0.+#aar'
You then do not want to add the compile 'com.android.support:recyclerview-v7:+' to your build.gradle as you will get that through RecyclerViewLib.
I just ran into this problem. This can happen when your min sdk version and built targets are set to a higher API level/OS version than your phone is running. If you're using Android Studio, go to File > Project Structure > and edit relavent settings then Run again.