I am trying to run "BitmapFun" official example but getting the following errors:
1)Cannot resolve symbol KITKAT
2) Cannot resolve method getAllocationByteCount()
Any help ?
My AndroidManifest.xml :
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
and here is the code :
#TargetApi(VERSION_CODES.KITKAT)
public static int getBitmapSize(BitmapDrawable value) {
Bitmap bitmap = value.getBitmap();
// From KitKat onward use getAllocationByteCount() as allocated bytes can potentially be
// larger than bitmap byte count.
if (Utils.hasKitKat()) {
return bitmap.getAllocationByteCount();
}
if (Utils.hasHoneycombMR1()) {
return bitmap.getByteCount();
}
// Pre HC-MR1
return bitmap.getRowBytes() * bitmap.getHeight();
}
You'll need to set the build SDK version to 19 (4.4) or higher to have API level 19 symbols available while compiling.
First, use the SDK Manager to download API 19 if you don't have it yet.
Then, configure your project to use API 19:
In Android Studio: File -> Project Structure -> General Settings -> Project SDK.
In Eclipse ADT: Project Properties -> Android -> Project Build Target
the method bitmap.getAllocationByteCount() was introduced in API level 19.
if your project build target is less than API 19, it will give error.
try this...
1) select your project root folder and right click
2) go to properties -> android
3) select API 19 as your project build target and clean your project
Related
build.gradle has
minSdkVersion 8
I am trying to compile fresco which required minimumsdk 9
compile 'com.facebook.fresco:fresco:0.9.0+'
I get a sync error
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library ...
Suggestion: use tools:overrideLibrary="com.facebook.drawee.backends.pipeline" to force usage
I have tried adding it to the manifest override list and required false as shown below but get the same error.
<uses-sdk tools:overrideLibrary="com.facebook"/>
<uses-library android:name="com.facebook" android:required="false"/>
If i add the full path e.g. com.facebook.drawee.backends.pipeline then the build just fails on another sub path. I only intend to use fresco programatically on compatible devices and will not use it if device sdk is < 9 so how do i ignore it in the build validation
If you're using android studio, open the Build.gradle(Module: app) file and set the minSdkVersion to 9 there.
EDIT
Wherever you are trying to access the methods, first wrap in an API level check...
if(Build.VERSION.SDK_INT >= 9) {
//Do your thing....
}
To prevent the compiler from compaining, wherever you do this check, insert the following above the method decleration...
TargetApi(9)
for example...
TargetApi(9)
public void myFunction() {
if(Build.VERSION.SDK_INT >= 9) {
//Do you thing...
}
}
I'm trying to get around an annoying issue with Gradle that does not allow libraries to have different min/target sdk's. The solution was to add the following to build.gradle.
android.applicationVariants.all{ variant ->
// This is an annoying hack to get around the fact that the Gradle plugin does not support
// having libraries with different minSdkVersions. Play Services has a min version of 9 (Gingerbread)
// but Android Maps Utils supports 8 (Froyo) still
variant.processManifest.doFirst {
File manifestFile = file("${buildDir}/exploded-bundles/ComGoogleMapsAndroidAndroidMapsUtils03.aar/AndroidManifest.xml")
if (manifestFile.exists()) {
println("Replacing minSdkVersion in Android Maps Utils")
String content = manifestFile.getText('UTF-8')
content = content.replaceAll(/minSdkVersion="8"/, 'minSdkVersion=\"9\"')
manifestFile.write(content, 'UTF-8')
println(content)
}
}
}
However when i do that, I get an error that applicationVariants cannot be resolved. How do I fix this?
Aparrently, this is an Android Studio bug and is telling me there are errors where there's none. Building and ignoring works fine.
When building android apps for different behavior on different targets we can do:
if (Build.VERSION.SDK_INT < 10) {
Toast.makeText(this.context, "Not Supported", Toast.LENGTH_LONG ).show();
} else {
this.doComplicatedOperation();
}
But in the method doComplicatedOperation() it would be logical to use higher api classes than the current build target (eg. api 5), but lint keeps complaining that ClassIntroducedInApiLevel11 can not be resolved as a type
How could I change the code of doComplicatedOperation() that my project compiles?
#TargetApi(11)
private void doComplicatedOperation() {
ClassIntroducedInApiLevel11 = new ClassIntroducedInApiLevel11();
}
The purpose of minSdkVersion is to exclude platforms where you do not provide backward compatibility support.
In order to provide the proper libraries for your build you need to set a higher targetSdkVersion so the IDE or whatever knows what libraries to include when creating your APK.
It sounds like you don't want to target a higher SDK because some methods or objects may be deprecated or even unsupported. That's when you use support libraries, if necessary, for backward compatibility.
You need to change your SDK target to at least the SDK that the method is in so in. You should always be targeting the highest API there is available (currently 19) so your manifest should look like this
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="19" />
if you are still targeting SDK 5 you are in the dark ages
I want to check if the android version is above ICS:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
I have a code error,
ICE_CREAM_SANDWICH cannot resolved or it is not a field
But I can read here
http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
this is the correct way, where is the mistake?
Edit after Andy Res answer
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
But if I check Project->properties->Android, ICS doesn't appear, from Android 3.1 to Android 4.1. I suppose this is the error, how can I solve it?
But if I check Project->properties->Android, ICS doesn't appear, from Android 3.1 to Android 4.1. I suppose this is the error, how can I solve it?
Use the SDK Manager and download the SDK(s) that you want. They will then appear in the list for you to set your build target.
Simply use this
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 14){
Make sure the project build target is Android 4.0 or higher.
(Assuming you use Eclipse, you would do this by: Right clicking on the project -> Properties -> From the left menu click on Android -> then choose the target)
BACKGROUND
I am developing an android application that needs to work on API levels from 7 to 16.
THE PROBLEM
Whenever I go to build my project this is the process I have to go through.
Clean project
Run Project
"Errors in project" > Click OK > Run Project Again
Runs fine on any API
I think the problem is due to the fact I am including code (such as the ActionBar) that API < 3.0 can't use but I am checking for it and running something else if thats the case.
THE QUESTION
Does anyone know a way round this because it is very time consuming considering I have to do this every time I want to run it.
I suppose you are using Eclipse for your development. You can annotate the offending methods as follows:
private final int VERSION = android.os.Build.VERSION.SDK_INT;
private File myDir;
// some stuff here
#SuppressLint("NewApi")
private void doSomething() {
if (VERSION < 8) {
// Uses a method available since API 1
myDir = Environment.getExternalStorageDirectory();
else {
// Uses a method available since API 8
myDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
}
// Do more stuff
}
You can add in your manifest:
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" />
Then any API between and including 7 and 16 versions will compile because your target is 16.
Then if your device is 7 any API > 7 will fail on your device but you have said you are taking measures against that in your code.