Android studio give me message that i can use try with automatic resource management.
But the docs says
If you’re working on an app with minSdkVersion >= 19 and Java >= 7,
then you can use try-with-resources:
My project have minSdkVersion 15 and Java 1.8.
Do i need to ignore this message or to use try-with-resources?
You can use it.
Docs say the following:
In addition to the Java 8 language features and APIs above, Android Studio 3.0 and later extends support for try-with-resources to all Android API levels.
Sidenote, please drop support for anything below api 19.
Related
I know this has been asked before, but can not seem to find the answer in previous questions, so here goes.
I have created a project in Unity and exported it to Android Studio. I have set min API Level to 4.4 KitKat (API Level 19).
I have added: in the main manifest file. When building I get this error:
Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library [:UniWebView:] /Users/myname/.gradle/caches/transforms-2/files-2.1/97563e885486a53e4f6658e98b58f094/jetified-UniWebView/AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.onevcat.uniwebview" to force usage (may lead to runtime failures)
How do i set the compatible library to minSdk 19? It needs to be 19 and not 21 due to the fact that if I release the update with 21 almost 20% of my users will be unable to play the game :-/
Units not compatible with API level 21+ = 2054 (19%)
Actually... A side question... Should I be afraid of upgrading API in term of loosing users? I have a version using API level 21 which is ready to be released.
If I should be carefull with this, how do I solve initial issue?
hoping for help and thanks in advance :-)
You basically have 4 options:
Increase you project's minSdk to 21 and lose users
Add tools:overrideLibrary="com.onevcat.uniwebview" to your manifests's application tag, which will probably lead to runtime crashes for your API 19 users (please test the whole thing heavily if you choose this option!!!)
Throw away the library and find another one. Or write your own solution
Fork the library (in case it's open sourced) and try to decrease its minSdk to 19
If I were you, I'd go with option 3
I have an Android Xamarin appliation with android:minSdkVersion="15" and android:targetSdkVersion="21". Turned out that IDE (xamarin studio, visual studio) and compilation process just ignore if I'm using something above API 15 which is not expected behavior here.
For example there is a method Path.addArc(float,float,float,float,float,float) from API 21 and I was able to use it with the manifest settings above which gave me a run-time error NoSuchMethodError.
There is an easy fix to use an overload Path.addArc(RectF,float,float) from API 1 but my question is more about how to get a compile time error instead or a run-time.
[UPDATE]
Basically I want to maintain the backward compatibility for API 15 (minimum android version) while having API 21 as a target android version. And I want to get an IDE support when I'm trying to use any method above API 15. That means I need a warning saying that I'm using a method which doesn't exist in the minimum android version defined so please do a run-time version check.
Is it possible?
To get compile time warnings you need to set your Target Framework to the min SDK you want to support. This will give you errors when you try to use higher level apis. Open Project Options dialog. In this dialog, click Build > General
You can read about api levels here https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/#Target_Framework
If you just want to get an error while keeping the target framework the same you can modify your IDE preferences to throw a compile time error vs a warning.
I want to use data binding in my android studio project if its available in production. I am searching online and find references to a beta copy which I clearly dont want. But i read here that data binding is apart of api 23 and built into android studio ? how do i use it if this is true ? I cant find it on jcenter, is it something thats built into the IDE ?
I created a minimum sdk project of 21 and I'd like to use databinding. This code in xml wont compile:
<TextView android:text="#{user.name}"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="#user.isAdmin ? View.VISIBLE : View.GONE}"/>
the exact error is on the visibility line and it says "Missing /"
Does it only work on api 23 ? wouldn't this break on older devices then ?
I am searching online and find references to a beta copy which i clearly dont want.
It is in a release candidate state at this time.
But i read here that data binding is apart of api 23 and built into android studio ?
Data binding is supplied by the Android Support libraries and a Gradle plugin. It is not related to API Level 23. Android Studio support exists, to some degree.
This code in xml wont compile:
That is because you are missing the binding expression opening characters. Change that attribute to:
android:visibility="#{#user.isAdmin ? View.VISIBLE : View.GONE}"
Does it only work on api 23 ? wouldn't this break on older devices then ?
Quoting the documentation: "you can use it with all Android platform versions back to Android 2.1 (API level 7+)."
The Data Binding Library offers both flexibility and broad compatibility—it's a support library, so you can use it with devices running Android 4.0 (API level 14) or higher.
However data binding is supported on Android Plugin for Gradle version 1.5.0 and higher.
I recommend you to use the latest Plugin for Gradle in your projects.
to get started with data binding see https://developer.android.com/topic/libraries/data-binding/start.html
I research material design project for 4.x API, It seem too many problems in style values, always style.... (in v-21) not found. I think v-21 is only build with api 21. But I want to build for 4.x API, do anyone know problem?
Here is some project in Github i found:
https://github.com/wasabeef/awesome-android-ui
https://github.com/rey5137/material
I use eclipse too. Change ANdroid API 21,22,23 but it still not work
The Log say : no resource found that matches the given name "TextAppearance.Appcompat.Body1"
Here is my picture:
OTHER QUESTION:
The Author say this material project can run on API 2.x -> 4.x , but why it need to build with API 21 -> 23? So can lower device can run it?
Set compileSdkVersion 23 or 21 or above in your build.gradle file.
The Log say : no resource found that matches the given name
"TextAppearance.Appcompat.Body1"
This is because you might not have imported AppCompat Library to your Eclipse Project.
The Author say this material project can run on API 2.x -> 4.x , but
why it need to build with API 21 -> 23? So can lower device can run
it?
Yes, Its always a good practice to build your App with the latest API version as this will include all the updated resources which might be not available in previous versions of Android. However, this will not affect your APK size in anyways.
I have a App created on API 8. Now I want to make it work with ICS and for that I need additional imports which are not available in API 8.
I want to add following imports:
import android.provider.CalendarContract;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
So do I have to make a diffenent app just for API > 15? The name of the App should not change.
Or maybe it is possible to place 2 App versions and make the minSdkVersion and maxSdkVersion according to the API level into Google Play?
How do you handle that?
I have a App created on API 8.
Great!
Now I want to make it work with ICS and for that I need additional imports which are not available in API 8.
No problem! Since import statements are applied at compile time, so long as you set your project's build target (e.g., Project > Properties > Android) to API Level 14 or higher, your code will compile fine.
So do I have to make a diffenent app just for API > 15?
No. Just use version guard blocks to ensure that you do not try using the newer code on older devices:
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// do stuff with CalendarContract
}
Or maybe it is possible to place 2 App versions and make the minSdkVersion and maxSdkVersion according to the API level into Google Play?
That should not be necessary.
You want to add a compatibility shim to your existing app so that it works on lower API levels and is still able to access API's from higher levels.
In general, the way to do this is to isolate the code that uses the higher-level API's in classes that are loaded at run-time via reflection, only if the API level supports them.