Android Compatibility Build Problems - android

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.

Related

Tool to Check if code contains higher API calls than minimum level

I am working with a large project, which has a minimum API level:16. however, I came across API usages that are above API level 16.
Is there any tool in Android studio or elsewhere, other than testing with a device, to check if the code doesn't violate the minimum required API level or better point it out like an error etc.?
Thank you.
The IDE will use the minimum android SDK, thus you will not get compile errors. If you there are classes in SDK 14 which are moved in sdk 16, yet you are using the imports from SDK 14, it will give a standard compile error.
So no, not that I am aware of.
You can use something like this:
public static boolean supports(final int version) {
return Build.VERSION.SDK_INT >= version;
}
Like this,
if (supports(Build.VERSION_CODES.HONEYCOMB)) {
// do something HONEYCOMB+ compatible here
}
More codes here,
http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

Android "couldn't log to binary event log: overflow"

I have an android app that has been running without problems until I updated my device to android 4.4 (kitkat).
Now I start getting this error and some part of the program is broken with this in the log cat_
Android "couldn't log to binary event log: overflow"
Does anyone have any idea what is happening?
I don't know if you know this but 4.4 has some issues.
In order for it to work you will have to change your project's target SDK to 4.4 KitKat or if you haven't installed the version yet go into android manager and get the appropriate files.
Even then your app may not work, if it doesn't, downgrade your device to android 4.3 or whatever version your app was working at.
Hope this helps!
This may or may not help, but I was having this same issue. I was using Butterknife and not declaring the id on the #OnClick. After setting it, it worked and logged perfectly.
clue:
in 4.4.4 r1
/frameworks/native/services/surfaceflinger/EventLog/EventLog.cpp
58void EventLog::TagBuffer::log() {
59 if (mOverflow) {
60 ALOGW("couldn't log to binary event log: overflow.");
...
67}
That should be the problem
mOverflow = ture 's case :
e.g:
116void EventLog::TagBuffer::writeString8(const String8& value) {
...
118 const int32_t stringLen = value.length();
119 const size_t needed = 1 + sizeof(int32_t) + stringLen;
120 if (mPos + needed > STORAGE_MAX_SIZE) {
121 mOverflow = true;
122 return;
...
128}
STORAGE_MAX_SIZE = 128
your tag's text > char[128]
I think it is due to the shortage of hardware resources of the old equipment
New systems often require more memory space
Maybe it's the system ROM 's problem
or try curtail your TAG's lenth.
or mabye is not your APP's ErrorLog

How to use android apis higher than actual build target

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

Cannot resolve symbol KITKAT Cannot Resolve method getAllocationByteCount()

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

Lint and old API level warning

I compile against Android 4.2 (API 17), in my Manifest I have:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"/>
In code I use:
String first = sdf.format(new Date(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime));
Field firstInstallTime was introduced in API 9.
Lint does not warn me, i.e. that this field is not valid in API 8. What am I missing, how should one detect this?
If I compile against Android 2.2 (API 8), I find the error and a bunch of extra errors due to new features used (> API 8) and the project won't compile.
(I'm aware of handling such things in runtime with for example Build.VERSION.SDK_INT)
What's the best way of working?
Why is lint not working?
Thanks!
This answer may be late but You should check your lint preferences
Right click on project -> Properties -> Android Lint Preferences
then search for min in the searchbox and select "UsesMinSDKAttributes"
Finally select "Include all" button. Hopefully the check had just been surpressed (Something I've had to do just to fix a silly lint error)
Good luck.
If it is intoduced in api level9 then try this.
< uses-sdk android:minSdkVersion="9" android:targetSdkVersion="10"/>
Probably it will works when the https://code.google.com/p/android/issues/detail?id=56427 will be solved

Categories

Resources