This is a Marmalade based question
I am building my android extension which is using symbols added in API level 16 and above.
When building it I get the "cannot find Symbol" error for those new classes.
How do i tell the MKB to take the set the new API level as the target sdk when building an extension
running following command
mkb AndroidNotification_android_java.mkb --rebuild
and i get
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){
^
../source/android/C2DMReceiver.java:216: cannot find symbol
You'll have to change target API level from Android Manifest.xml file Make the target at highest API level available (currently 19)
Related
I want to add flutter_sound_lite to my application, Currently my Android API level is 16 and iOS target is 9.0
Flutter Sound requires an iOS 10.0 SDK and Android API level 21
I want to keep my API level (16) and iOS target(9.0), and add Flutter Sound too, just don't use it on old devices, How can I do it?
For android I add the following line in manifest
<uses-sdk tools:overrideLibrary="com.dooboolab.fluttersound, com.dooboolab.TauEngine" />
But in android log cat I have error
04-17 10:27:08.182 2973-2973/ir.karget E/dalvikvm: Could not find class 'android.media.AudioAttributes$Builder', referenced from method androidx.core.app.NotificationCompat$Builder.setSound
I am confused about the target build and sdk usage
Lets say I have this code
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
//do xyz
}
Let say that I built against API 19 (kitkat) and my target api in manifest is 19 and my minimum supported api is 9
Now if a device with API 9 runs the above code, will it crash? I expect the answer is yes becasuse it will not understand what Build.VERSION_CODES.KITKAT means. However, what's the point of the check above then in first place?
Please help clarify this
Thank you
It won't crash. Simply the code within the if won't be executed. Build.VERSION_CODES.KITKAT is a constant field, and as you can read here, the constant fields are replaced with the numbers themselves by the compiler.
lesser versions of android will use the support library, if the check for kit-kat fails, it will revert to the closest possibkle form that version supports.... via the support library...
you cannot run you app on anything less than the minimum version, but it will find a way to run with less than the target version as long as its aboe the minimum
No, it won't crash, because its Build.VERSION.SDK_INT value is 9. It simply will not enter inside your if clause. Only devices that have API version 19 or above will run your code inside the if. Build.VERSION_CODES.KITKAT is equal to 19.
The code you posted won't crash because the class Build is created and compiled for every build of your app (as the R file) depending of the target API you set in the manifest
As you setup your target API to 19, the Build class will contain the field Build.VERSION_CODES.KITKAT because it exists starting from API level 19.
I'm quite new with Android development, and I wanted to learn a bit about Lint tool and NewApi check. After doing some tests I'm a bit confused though.
After creating new Android application project in IntelliJ IDEA, I added some code to the onCreate method, so it now looks like this:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display d = getWindowManager().getDefaultDisplay();
Point size = new Point();
d.getSize(size); // API level 13
isDestroyed(); // API level 17
NativeActivity nativeActivity = new NativeActivity(); // API level 11
nativeActivity.getContentResolver(); // API level 11
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); // API level 9
boolean canDisableShutterSound = cameraInfo.canDisableShutterSound; // API level 17
}
In the manifest file I have
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" />
After compiling the project and running lint from command line:
lint --check NewApi --classpath c:\_dev\TestNewApi\out c:\_dev\TestNewApi
I got the following output:
Scanning TestNewApi: .......
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): android.app.NativeActivity#getContentResolver [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): new android.app.NativeActivity [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): new android.hardware.Camera.CameraInfo [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Field requires API level 9 (current min is 7): android.hardware.Camera.CameraInfo#canDisableShutterSound [NewApi]
4 errors, 0 warnings
So no complaints about getSize and isDestroyed methods. And after changing minSdkVersion to 9, the check result is:
Scanning TestNewApi: .......
No issues found.
It looks for me, like only the classes are checked in both cases, and if the class was introduced at or after minSdkVersion, then everything is ok. Is this the expected behavior? Or maybe I'm missing something?
Is this the expected behavior?
IMHO, no. I see the same behavior in Eclipse, and IMHO this is a bug. Normally, Lint will complain about methods that are newer than your android:minSdkVersion or #TargetApi(). I'm not quite certain why it is not doing that here.
I have filed an issue related to this.
Some Java library methods like DecimalFormat.setRoundingMode have a #since 1.6 entry in their documentation.
/**
...
* #since 1.6
*/
public void setRoundingMode(RoundingMode roundingMode) {
...
}
When I tried to use this method compiled under Android 4.2.2 and JDK 1.6 with my android:minSdkVersion set to 7 as shown,
myNumberFormat.setRoundingMode(RoundingMode.DOWN);
Android Lint underlined setRoundingMode in red for me and told me that
Call requires API level 9 (current min is 7): java.text.NumberFormat#setRoundingMode
How and why can the Android API restrict which Java library methods I can and cannot use? I cleaned my project and the Lint error disappeared. My project compiled with no errors and ran on a device running Android 2.2.3 (API 8).
My program crashed with:
05-09 11:32:38.436: E/AndroidRuntime(2074): Caused by: java.lang.NoSuchMethodError: java.text.NumberFormat.setRoundingMode
The Android documentation confirms that setRoundingMode, copySign, and others were added in API level 9. Does that mean that devices running Android OS level 8 and below are specifically compiled/built with JDK 1.5?
And I can understand that. But is it impossible for the Android Support Library (or anything else) to allow us to use these methods?
Related to Rounding Half Up with Decimal Format in Android
I am trying to run the Arduino ADK + Android examples (analogRead, digitalWrite, etc.) But I am getting the following compile error:
-compile:
[javac] Compiling 3 source files to C:\Users\???\AppData\Local\Temp\android7678598093798196219sketch\bin\classes
[javac] C:\Users\???\AppData\Local\Temp\android7678598093798196219sketch\src\processing\android\test\adk_analogRead.java:28: cannot access com.android.future.usb.UsbAccessory
[javac] class file for com.android.future.usb.UsbAccessory not found
[javac] arduino.connect( arduino.list()[0] );
[javac] ^
[javac] 1 error
I did some research and found this 9 months old post - http://forum.processing.org/topic/how-can-you-specify-the-target-api-level - where it talks about recompile Processing from source. However, I'm using version 2.0a5 and the team has already changed the source to use API level 10. (I also verified the generated code when I look inside the manifest xml file in temp folder.) Any idea how to fix this?
Just in case, I've successfully compiled and ran regular Processing app and deployed to Android (Nexus One.)
I think you need to use Google Android Api 3.1+
To use ADK, you can use API Level 10, but it needs to have the Google APIs attached (same thing you need to use Maps in your application).
If you're having trouble enabling the Google APIs, try switching to API level 12, where you no longer need the addon. However you'll now be using the android.hardware.usb library instead of com.android.future.usb.
Here's what I did to get the ArduinoAdkUsb examples to compile:
In Processing, switch to Android Mode
In Processing, go to Android -> SDK Manager
In SDK Manager, install Android 2.3.3 (API 10) -> Google APIs if not installed
Copy sdk/add-ons/addon-google_apis-google-10/libs/usb.jar to Processing/libraries/ArduinoAdkUsb/library/
Restart Processing