Android: able to install app for unsupported Android version - android

We're dropping support for Android 2.3 (API level 9) devices because most of our users have a newer Android version on their phones. I've updated the minimum SDK version to api level 14.
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
}
However I'm still able to install the app on Android 2.3 devices manually (not by store). Is this expected behavior or am I doing something wrong? I couldn't find the answer somewhere else.
Another strange issue is that Lint doesn't detect the correct api level.
listView.setFastScrollAlwaysVisible(true);
This results in the warning: Call requires api level 11 (current min is 9).
However my current minimum is now 14. So this indicates to me that i did something wrong. I tried cleaning and rebuilding the project, restarting Android Studio. It all didn't work.
Can anyone help me out?
Edit
Based on Sufians comment I started fiddling around with my gradle files and I came to the following solution. However some questions still remain.
My project structure looks like this:
android.gradle (top-level build file which contains SDK versions)
main module (contains base code for other modules)
build.gradle (apply from: '../android.gradle')
sub module A (module specific changes)
build.gradle (has dependency on main module)
sub module B (module specific changes)
build.gradle (has dependency on main module)
I have a top-level build file android.gradle which contains the SDK versions. My modules then include the build file by apply from: '../android.gradle'. If I put the minSdkVersion directly in de main module the warnings disappear. Is that the way it should be? or do I need to set an minSdkVersion for every submodule? Or is there another way so that the SDK versions can stay within the android.gradle file?

Ok... I finally realized that there is nothing wrong in my project structure. The only thing I needed to do was press the little 'Sync Project with Gradle Files' button. After that all errors disappear.
Also I concluded that it's possible to install unsupported apps manually.
However the Google Play Store should prevent users from installing or updating the app.

i have personally never developed anything for android but when installing apps the device has never complained when installing an .apk that wasn't supported by the OS version.
even when the store said it wasn't supported i'm always able to install it as a .apk so i think it can't really be blocked.

Yes, you can install the app manually on your device as long the minimum API level specified in your manifest is less than your device's API level.
When you upload your app to the store, the store will not show your app to users with devices having Android version less than the min API level specified (API level 9 in your case).
As for the Lint warnings, make sure that the minimum/maximum SDK versions in your manifest file match those specified in the build.gradle file.
and you can also make sure that new APIs are not executed on older API levels by checking the OS version in the code.
http://developer.android.com/reference/android/os/Build.VERSION.html

If I put the minSdkVersion directly in de main module the warnings
disappear. Is that the way it should be?
Your main module's minimum and target SDKs (i.e inside the build.gradle of the module) will be that of your application.
The project's build.gradle should not contain any of this information.
or do I need to set an
minSdkVersion for every submodule? Or is there another way so that the
SDK versions can stay within the android.gradle file?
Each module defines its own minimum SDK. If you're using a third party module/library, you better not change it, unless you know what you're doing.

Related

How does Android Studio know about backwards compatibility issues?

I am trying to understand how Android Studio determines if a code is available in a certain API. When using MediaStore.setRequireOriginal, Android Studio warns me that "this call requires API level 29". Does Android Studio check that this code is available in previous Android version sources?
photoContentUri = MediaStore.setRequireOriginal(photoContentUri)
I am trying to understand how it knows this.
The linter just knows all the APIs in all the versions. You don't need to download all the previous Android version sources (I was wondering how Android Studio's Linter knew about older versions when I only had API level 29 and 30 sources downloaded on my machine).
As you can see, lint now has a database of the full Android API such that it knows precisely which version each API call was introduced in.
Lint API Check page
The Short Answer:
It's set by the developer, And Android Studio just compares your minSdkVersion set in build.gradle file with the required api level.
The Longer Answer:
When you get this warning on a method, just CTRL+click on it to go to the source class, and there you will find it annotated #RequiresApi or/and #TargetApi, for example :
class MediaStore{
#RequiresApi(api = 29)
#TargetApi(29)
void setRequiredOriginal(...){}
}
Your build.gradle file:
defaultConfig {
minSdkVersion 23
...
}
Android Studio compares minSdkVersion to #RequiresApi or/and #TargetApi at the time you call the method MediaStore.setRequiredOriginal(...); and warn you if minSdkVersion is less that the recommended api.
Please note that there are differences between #RequiresApi and #TargetApi, sometimes you find them used along with each other but sometimes just one of them.
For more about difference between the two see: https://stackoverflow.com/a/50578783/10005752
There is something in build.gradle of application module like:
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
}
So you can change the "minSdkVersion" to 29, and the warning message disappear ...
And if not:
With android OS version >= 29: your code works normally
With android OS version <29: might be an exception occurs

Android Studio Error when building apk file [duplicate]

When trying to build OpenStreetMapView from git://github.com/osmdroid/osmdroid, I get this error:
failed to find target with hash string android-23: D:\Users\myusername\AppData\Local\Android
How can I fix this? Previous questions similar to this suggest checking that android 23 is not installed, but in my case, it is.
Below is some pertinent info:
ANDROID_HOME is D:\Users\myusername\AppData\Local\Android\sdk
D:\Users\myusername\AppData\Local\Android\sdk\platforms\ contains the directory \android-23\, (as well as android-19, android-21, android-22, android-MNC)
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "org.osmdroid.example"
minSdkVersion 8
targetSdkVersion 23
versionCode 16
versionName "4.4-SNAPSHOT"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
}
lintOptions {
abortOnError false
}
}
dependencies {
compile 'android.support:compatibility-v4:23+'
compile project(':osmdroid-android')
//compile 'org.osmdroid:osmdroid-third-party:4.4-SNAPSHOT'
}
I tried changing targetSdkVersion and compileSdkVersion to 22. This causes the error message to change to "android-22" instead of "android-23".
SDK Manager:
In my case, clearing caché didn't work.
On SDK Manager, be sure to check the box on "show package descriptions"; then you should also select the "Google APIs" for the version you are willing to install.
Install it and then you should be ok
In Android Studio File -> Invalidate Caches/Restart solved the issue for me.
The answer to this question.
Gradle gets stupid from time to time and wiping out the cache is the only solution that I've found. You'll find a hidden .gradle folder under your user home folder and another one wherever the checkout location is for osmdroid.
I fixed the issue for me by opening the Android SDK Manager and installing the build tools for all 23.x.x versions.
See the screenshot.
Update: Does not apply to the Android Studio released after this answer (April 2016)
Note: I think this might be a bug in Android Studio.
Go to Project Structure
Select App Module
Under the first tab "Properties" change the Compile SDK Version to API XX from Google API xx (e.g. API 23 instead of Google API 23)
Press OK
Wait for the completion of on going process, in my case I did not get an error at this point.
Now revert Compiled Sdk Version back to Google API xx.
If this not work, then:
With Google API (Google API xx instead of API xx), lower the build tool version (e.g. Google API 23 and build tool version 23.0.1)
Press Ok and wait for completion of on going process
Revert back your build tool version to what it was before you changed
Press Ok
Wait for the completion of process.
Done!
Following these reccomended directions seemed to work:
Hint: Open the SDK manager by running: /path/to/android/tools/android
You will require:
1. "SDK Platform" for android-23
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)
There are 2 solutions to this issue:
1) Download the relevant Android SDK via Tools -> Android -> SDK Manager -> SDK Tools (ensure you have 'Show Package Details') checked. Your case would be Android 6.0 (Marshmallow / API level 21)
2) Alternatively, open your build.gradle file and update the following attributes :
compileSdkVersion
buildToolsVersion
targetSdkVersion
either to the most recent version of the Android API that you have installed / another installed version you'd like to use (although I'd always recommend going with the latest version for the usual reasons: bug fixes etc.)
If you're following step 2 it's also important that you remember to update the Android support library version if your app is using it. This can be found in the dependencies section of your build file and looks something like this:
compile 'com.android.support:appcompat-v7:27.0.2'
(replace 27.0.2 with the most recent support library version for the API level you intend to use with your app)
Had the same issue with another number, this worked for me:
Click the error message at top "Gradle project sync failed" where the text says ´Open message view´
In the "Message Gradle Sync" window on the bottom left corner, click the provided solution "Install missing ... "
Repeat 1 and 2 if necessary
23:08 Gradle sync failed: Failed to find target with hash string 'android-26' in: C:\Users\vik\AppData\Local\Android\Sdk
Android SDK providing a solution in the bottom left corner
For me the problem was in that I wrote compileSdkVersion '23' instead of 23. The quotes were the problem.
It worked for me by changing compileSdkVersion to 24 and targetSdkVersion to 24 and change compile to com.android.support:appcompat-v7:24.1.0
This poblem is solved for me after Run as administrator the Andorid Studio
Open the Android SDK Manager and Update with latest.
Nothing worked for me. I changed SDK path to new SDK location and reinstalled SDK.Its working perfectly.
Tools > Android > SDK Manager.
I had this issue when using windows. It turned out that the SDK location in my profiles was the issue. So I had to relocate my SDK folder to documents and then it worked.
Mine was complaining about 26. I looked in my folders and found a folder for 27, but not 26. So I modified my build.gradle file, replacing 26 with 27. compileSdkVersion, targetSdkVersion, and implementation (changed those numbers to v:7:27.02). That changed my error message. Then I added buildToolsVersion "27.0.3" to the android bracket section right under compileSdkVersion.
Now the make project button works with 0 messages.
Next up, how to actually select a module in my configuration so I can run this.
Download the specific Android release from the link specified in the build console.
The problem is caused because the code you are running was created in an older API level, And your present SDK Manager doesn't support running them.
So do try the following;
1.Install the SDK Manager that support API level 23.
Go to >SDK Manager, >Android SDK , then select API 23 and install.
2.second alternative is to update your build.grade app module to change
compileSdkVersion,compile,and other numbers to your currently supported API level.
Note:please ensure to check the API and Revision numbers and change them exactly. otherwise Your project won't synchronize
Ensure the IDE recognizes that you have the package. It didn't on mine even after downloading 28, so I uninstalled then reinstalled it after realizing it wasn't showing up under File-Project Structure-Modules-App as a choice for SDK.
On top of that, you may want to change your build path to match.
Slightly related, the latest updates seem able to compile when I forced an update all the way to 28 for CompileSDK, and not just up to the new API 26 min requirement from Google Play. This is related to dependencies though, and might not affect yours
AndroidSDK > SDK platforms > and install API Level 23

Set the supported lowest supported Android version in a Nativescript app.

I've deployed a Nativescript app to Google Play for my beta testers to use. My app is only intended to support Android version 4.4 and above. So I thought setting this in the AndroidManifest would get the job done.
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="__APILEVEL__"/>
Yet once deployed the Play store is still saying that those running Android versions lower than 4.4 can still download the app. What else do I need to do to prevent this?
Follow the thread below where a solution is shown on how to modify your minimum SDK version with app.gradle
https://github.com/NativeScript/android-runtime/issues/575#issuecomment-251584253
Basically as Plamen5kov has shown, you have to do the following:
what you can do is go to app/App_Resources/Android/app.gradle and
change the default configuration to meet your requirements.
android {
defaultConfig {
minSdkVersion 19 ....
Gradle overrides the AndroidManifest.xml that's why you need to change
the configuration in gradle, rather than in the manifest file.

Can I use Widgets from support library of Android L Preview in current Android Version?

I am trying to use RecyclerView & CardView in existing Android version. They said it is in support library. So, I should be able to use those with put "compileSdkVersion" to "Android-L". Right ?
I am trying to use those widgets without Android L Preview device or emulator.I have checked other questions on this matter. But, seems they all are trying Android-L with Android-L version.
Here is my dependencies.
compile 'com.android.support:support-v4:13.0.+'
compile 'com.android.support:recyclerview-v7:+'
Here is my target config
minSdkVersion 15
targetSdkVersion 20
Thanks in advance for any idea.
I just found the solution.
The reason why I can't build the App with RecyclerView & CardView while the targetSdkVersion and minSdkVersion is not "Android-L" is because internally Google designed to treat the preview version of OS differently comparing with original releases.
When I compile the App which contains the components from Android-L, the build tools locked minSdkVersion and targetSdkVersion to same level. The new supports libraries (RecyclerView, CardView, Palette, etc) are also locked into the L API level.
This behaviour is only happening on this Android-L preview release.
The fix for it is to put the following in AndroidManifest.xml.I didn't need to change anything on my gradle script.
<uses-sdk
tools:node="replace" />
Since version 0.11 of Android Gradle Plugin, it turned on a new Manifest Merger by default. It allows us to do some niffy stuffs. This specific configuration tells the manifest processor to replace any attributes from uses-sdk nodes in lower-priority manifest (such as library manifest in this case) with this attributes.
Since Gradle also inserts minSdkVersion and targetSdkVersion from your build.gradle into this uses-sdk node, that's all we really need to add.
Check here for more information related to this issue.
Check here for the info related to Manifest Merger.
The best solution is RecyclerViewLib. The support library has been pulled into a repo and published on maven central. It'll be safe even after L is released as all L dependent code has been removed. The author explains it here in his blog post.
To use it in your project just add the following line in your build.gradle dependencies:
compile 'com.twotoasters.RecyclerViewLib:library:1.0.+#aar'
Good luck!
No you must set targetSdkVersion above 7. You can use android support library v7 with project that support android above 7 api level.
And one more. Android L has api level 'android-L', not 20. Under the hood it has api level 21 (20 is 4.4W, KitKat for wearables).

Build target with API level below 14 and v7 appcompat library

Having issues with appcompat-v7 and compileSdkVersion, the app build target is API 10 so I set compileSdkVersion 10 to compile the code safely, as expected it works well with support-v4: the app compiles and runs on API 10 devices.
Then I want to add appcompat-v7 to dependencies (or replace v4 with it) and perform clean re-build of the app without any changes at the code or resources, build fails at the R generation stage unless the compileSdkVersion is set to a higher value.
I understand it as the v7 library is using some values unavailable at API 10. It raises the question of how someone can continue to write safe code and use v7 without need to manually check API level of each variable and method. Is there a way to keep using v7 (that is claimed to be "designed to be used with Android 2.1 (API level 7)") and compileSdkVersion 10 ?
Apparently at the newest Intellij version Lint produces errors if the methods form the API above minSdkVersion is used (can be enabled/disabled at Preferences-Inspections, expand Android Lint at the list, look for Calling new methods on older versions or use "NewApi" annotation to suppress the error if needed).
That'll have to do until some kind of dynamic resources compilation is introduced. I'm going to leave the question here for a future reference.

Categories

Resources