I have dependency on a library, which has ic_launcher.png[for all densities] as drawable. My project also has ic_launcher.png for all densities].
I reference the drawable in xml. It works in api level 23,16. I have galaxy tab api 19. It picks up the ic_launcher from the library.
I tried to clean and build. But the issue remained.
How to fix this issue? Apart from the workaround of renaming my drawables.
Related
Whenever I create an ImageView with icon added using Android Studio's Vector Assets, I'm getting an error at the line app:srcCompat="#drawable/ic_play"
When I change the app:srcCompat with android:src, the error is gone but the icon looks pixelated.
What is the main difference between
app:srcCompat="#drawable/ic_play"
and
android:src="#drawable/ic_play"
app:srcCompat
is the most foolproof method of integrating vector drawables into your app.Vector drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices
Note
As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat .
you need to add vectorDrawables.useSupportLibrary = true to your build.gradle file
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
android:src
Sets a drawable as the content of this ImageView.It will display in
its original size. No automatic scaling .
If you are using android:src="#drawable/some_vector" without vectorDrawables.useSupportLibrary = true in build.gradle file and your app have vector images (vector drawable), then while building the apk file Android gradle plugin generates a lot of *.png files for different screens (hdpi, xhdpi...) from each of your vector drawable (only for API =< 19). The result - bigger size of apk.
When using app:srcCompat="#drawable/some_vector" with vectorDrawables.useSupportLibrary = true android uses vector drawable files without generating *.png files.
You can check this with Android Studio apk analyzer tool. Just build apk with and without vectorDrawables.useSupportLibrary = true.
I think this is the main difference.
Use:
app:srcCompat="#drawable/backImage"
The srcCompat attribute is actually defined within AppCompat library.
Important: you will need to add the appropriate namespace for this.
xmlns:app="http://schemas.android.com/apk/res-auto"
Note
What you are getting seems to be just a lint error that can be ignored. I have tried and gotten the same error, but it is working correctly.
You can use tools:ignore="MissingPrefix" to avoid seeing this error, temporarily.
I hope this helps.
app:srcCompat="some_resource"
is refer that it is AppCompatActivity src which comes in support library while
android:src="some_resource"
refers to simple activity.
Vectors and animated vectors were only supported in recent versions of the framework. srcCompat can be used with the compatibility library to make them work, but this only works with the certain views in the support library. Notice that app: is used instead of android:. This means its not part of the framework, but a parameter defined by your app.
Android 5.0 (API level 21) and higher provides vector drawable support so in order to support vector drawables in older versions app:srcCompat was added
I was able to create a new project In Android Stdio which ran fine.
Then I copied many of the files from an old project into it, and tried to run it, but I got this error about AppTheme:
It talks about values-v21.xml which I didn't have before. What is that file? And how can I get around this issue?
Thanks!
In your Manifest file. Change,
android:theme="#style/AppTheme"
To,
android:theme="#style/AppBaseTheme"
I think the problem is the file name. Your file is named "values-v21.xml", all the android projects I saw had that file name as "styles.xml" and was included inside the v21 folder. Also I included an image. Sorry for the poor resolution.
Also, v21 means that it's for API Level 21 and above. API Level 21 is Android 5.0 (Lollipop). For more info on API Level 21: http://developer.android.com/about/versions/android-5.0.html
I hope this fixes your problem.
I am trying to modify my widget so that it supports being placed on 4.2 lockscreens. However I still want to support older SDK's.
I added
android:widgetCategory="keyguard|home_screen"
to my appwidget-provider in res/xml, but eclipse complains that there is "no resource identifier found for attribute widetCategory in package android'
If I raise the minSdkVerion to 17 everything works fine, but I want to still support older SDKs.
I have tried using resource qualifiers creating a separte res/xml-v17/mywidget.xml and only adding the tag there, but the error still appears.
Thanks for any help.
Edit:
I figured it out. using a res/xml-v17/ folder is the answer. I just had to change the build target for my project to 17 / 4.2.
I think that setting targetSdk to 17 is enough. XML elements that do not make sense on older SDKs are simply ignored.
No need to put mywidget.xml into res/xml-v17 folder
Put a copy of your mywidget.xml in res/xml-v17/ folder.
This targets Android 4.2 and all new "properties on the appwidget-provider element will be avaible. Also right click your project in eclipse and change build target to: API level 17/ Android 4.2
I saw your Edit. But i think this makes it more clear that this question have an answer.
UPDATE: I can confirm Tomáš Hubálek answer. the xml-v17 is not needed. Changing Build target is enough. Right click your project in eclipse and change build target to: API level 17/ Android 4.2
So, I coded my entire app in Android 4.0.3. I used AmbilWarna color picker. Then I got this requirement to reduce the SDK requirement for Android 2.3. This is the point when EVERYTHING was working fine and superb
I have downgraded teh minimum SDK requirement. Everything runs fine except as soon as I include Ambil Warna as a library on my project, I start getting the error everywhere R is used, Saying that R cannot be resolved to a variable.
Upon a loot on the Console, this is what seems to be the real cause of the problem:
AmbilWarna\res\layout\ambilwarna_dialog.xml:18: error: No resource identifier found for attribute 'layerType' in package 'android'
I have set the Android SDK to 3.2 for AmbilWarna library project and on my project its at 2.3
Does anyone have any idea?
this is regarding this: http://developer.android.com/reference/android/view/View.html#attr_android:layerType
you are just trying to use a property for android that is not available on that api of the layout parser.
I just checked out the colorpicker code you are trying to use, and it's project.properties says it's written for target API-17 (android 4.2) and i'm tryng to compile it for API-10 (android 2.3.3)
simply remove those parts.
my diff
--- a/AmbilWarna/res/layout/ambilwarna_dialog.xml
+++ b/AmbilWarna/res/layout/ambilwarna_dialog.xml
## -19,7 +19,7 ##
android:id="#+id/ambilwarna_viewSatBri"
android:layout_width="#dimen/ambilwarna_hsvWidth"
android:layout_height="#dimen/ambilwarna_hsvHeight"
- android:layerType="software" />
+ />
and hope it's not mentioned in the code :)
I've had a lot of troubles too with my external libraries. What usually helped are one of these or multiple steps of these connected:
Delete ALL R.java imports in your Classes (there must not be any of them)
In Eclipse: Source => "Clean Up"
In Eclipse: Project => "Clean..." (This will rebuild your project from scratch and therefore regenerate your R.java)
Manually delete all R.java and save (located in /gen/)
Delete your external library project and readd it.
Step 3 usually did the job for me.
Also be aware that your minSdkVersion and targetSdkVersion fit to your library project (and the guidelines which are included)
I had the same problem, I thought I could just build and include the third party jar file and bring this over to my project - this resulted in the same problem as you - AmbilWarna\res\layout\ambilwarna_dialog.xml error: No resource identifier found for attribute 'layerType'.
To fix it I copied over the source files and all resources into my project (images/layouts etc etc), hey presto it worked.
Thanks http://code.google.com/p/android-color-picker/ for a nice clean easy to use colour picker!!
Nothing too exotic. I have classes in a library project, which is set to "Is Library".
The target application project uses this library under the Project Properties/Android section. The project is set to version 2.1-Update (api 7).
None of the classes from the library are visible in the target project. i.e. import statements referencing the classes are underlined in red.
Any ideas?
Try restarting eclipse also try selecting and applying different API level for the project, then apply, then change API level back. I sometimes seen such a problem, usually these actions help.
If your library name has a space in it, remove it.
Using MOTODEV Studio 1.2 and with the same problem.
But changing from Api Level 7 to 8 and changing again (setting up the Lib again) it starts to work.
In your project you have a src directory from your library.
Try refreshing it.
Make sure the classes in your library are declared public. That fixed this problem for me.