How to make imported projects use older api level? - android

I have a relatively old android device that works under api level 15, and I want to make some simple programs for it. Right now I just watch examples. I'm importing them from the sdk/samples/android-15 directory via the import command, they are imported as android-21 projects, then I go to module config and change api level to 15. This seemed to long for me, so I tried to fix it by deleting all sdk except 15. Now it doesn't import at all.
Where I can tell android studio to use sdk 15?

You dont need to change anything in the module configuration.
Go to your build.gradle file and check the next:
compileSdkVersion 21 //the version of the API the app is compiled against
buildToolsVersion "21.1.2"
defaultConfig {
// put here the minimum Api version compatible, in your case 15 or lower
minSdkVersion 15
targetSdkVersion 21
}
dependencies {
//be sure you add the dependencies with the support library
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
}
have you enabled the developer options in your device?
http://developer.android.com/tools/device.html
SDK manager: Check out that you didn't delete the minimun sdk tools required:
http://developer.android.com/sdk/installing/adding-packages.html
You dont need to download all the api version abailable, those are

Related

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

Android Studio - Unable to run app on device minSdk(API 23, N) != device Sdk(API 22)

so i reinstalled linux on my computer and after i reinstalled android studio i tried getting an app that i wrote on to my phone which previously had not been a problem. The App ist targeted at devices with API 16 or higher but apparently Android Studio now features something called N preview which does not let me run anything on my phone. specifically when i hit the run button it tells me that
minSdk(API 23, N) != device Sdk(API 22)
i know this seems as though the target API isnt set correctly but when i started the project i set it to 16. Now how do i get around this? Also whats the cleanest way to change the target API on a project? Do i just change the build gradle?
Thanks a lot!
app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-N'
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.josias.myapplication"
minSdkVersion 16
targetSdkVersion 'N'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.+'}
Change
compileSdkVersion 'android-N' to compileSdkVersion 22 and targetSdkVersion 'N' to targetSdkVersion 22
The same happened to me on Android Studio, so I could not start a new emulator.
I had to:
Gradle Scripts -> build.gradle (module:app) -> minSdkVersion 14
(update "minSdkVersion" value to "14".
Now I am able to start a new emulator.
See the explain of CommonsWare. The key point is a preview version, so
older level device was prevented to install app anyway when using N compileSdkVersion.
This wortk for me in Android Studio: hold ctl+alt+shift press 'S', This will open project structure. Click on the tab 'Flavors', check in min sdk version if appear a version of your device sdk if you see select it and click 'OK', but if you didn't see a option for your sdk device click on cancel. Go to build.gradle(app) file and type in the min sdk version the version of your sdk device(android studio will recomend you to intall the version sdk). After that hold ctl+alt+shift press 'S' and the version sdk min will be there, just select it and click 'ok'. :)
check your build.gradle file to ensure the proper min sdk is set...android studio overrides the manifest with the build.gradle
I renctly encountered this problem, and this is very strange, on the other thread there's people suggest you should change you usb setting to "MTP/FTP" or something, this doesnt make sense and dont work out on my case.
After search some example case in this problem, I found that most of people have this problem when minSDK/'targetSDK'/'compileSdkVersion' is not a int but a letter.
I changed my MNC/N' to 23, andbuild - clean build`, problem solved.
hope it can help someone.
Change the minSdkVersion to your target device sdkVersion in build.gradle(Module:app)file will be appear on left side in Gradle Scripts.. Ex: minSdkVersion 24 //change the version value to ur target device value(like 23 or 22 or 21 or etc)
According to your configuration you have to change the minSdkVersion 23 to minSdkVersion 22, becoz your target device at API LEVEL 1
you can do a thing just open the sdk manager since i had one and just install ,the ÄNDROID N (API 23 N PREVIEW PACKAGES) give it a try instead of changing the gradle files
Changing the minSdkVersion may not always help. Check your SDK Manager, as already suggested, and make sure that you have the necessary versions installed as well (I had changed mine in Gradle, but it only made things worse on my end).

failed to find target with hash string android-23

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

Android Studio: How to debug older version of Android SDK step-by-step

I have an Android project targetting the Android SDK v21. Now I need to debug it on a device with Android 4.4 (i.e. SDK v20). How do I tell Android Studio to attach an older version of the source to the internal classes so that I can step through them?
Here the best solution is to set compile SDK version to 20. So that build tools will compile your project using SDK version 20 and you can debug your app.
When you use several modules in your project you need to set same compile SDK version to each module.
I can not confirm my answer works, but it is working for me.
I replace my compileSdkVersion, buildToolsVersion, minSdkVersion and targetSdkVersion with new one like following in my build.gradle file.
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.mytest"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
After changing it, you may not need to convert old to new or new to old sdk component.
You need to open module settings (Right click on your app module and select Open Module Settings or just select module and press ⌘ + ↓ on Mac)
And select compileSdk and buildTools to v20
Another way to do it is to open build.gradle file for the "app" module to change compileSdk and buildTools.
I would like to explain little before the solution.
Google provides the SDK APIs in the form of JAR (android.jar) files. The JAR files are stored at SDK LOCATION\platforms\android-API#.
For example the android.jar file for the Android 4.4(Kitkat) API-19 is located at YOUR SDK LOCATION\platforms\android-19\android.jar.
The Gradle compilation with the Android Studio uses the compileSdkVersion field in the build.gradle to select a specific android.jar for the compilation.
What is compileSdkVersion?
The version of the API the app is compiled against.
This means you can compile and use Android API features included in that version of the API
All the previous version features are also included during compilation.
If you try and use API 21 feature, such as public void openCamera (String cameraId, CameraDevice.StateCallback callback, Handler handler)
Added in API level 21 but set compileSdkVersion to 20, you will get a compilation error.
If you set compileSdkVersion to 21 you can still run the app on a API 20 device as long as your app's execution paths do not attempt to invoke any APIs specific to API 21.
How to set compileSdkVersion?
There are two ways
1. Selecting API from the GUI
1) Select "File->Project Structure..."
2) Select "app->Properties"
3) Set the "Compile Sdk Verion" from the drop down box to the required SDK version.
4) "compileSdkVersion" will be set automatically in the "app" module's
"build.gradle" file.
2. Setting the API in the gradle.build file
1) Open the build.gradle file of the "app" module
2) Set the compileSdkVersion to required value such as 19 for the API#19.
I hope that helps...
Happy Coding...
The best solution for me was to add a new module (Android Library) to the project and set the compile SDK to the requested api level. That way you can still compile your main app with the original SDK level but still get the sources integrated with your debugging Android version.
You can create a new Android Virtual Device with the preferred API level and debug the application on it.
Simply open module settings and change compileSdk and buildTools to v20

How to make a gradle android app compatible with above api version

I have an app that works fine on API 19. However, I want it to work well in other API's as well. I'm targeting API 10 and above.
My gradle build looks like this:
android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
But when I run the app on API 10 the AVD manager says compatible: no
How should I change my build so that it is compatible for API 10 and above?
Your gradle config looks correct. Be sure to check your virtual device settings and compare to what you have defined in your manifest file. Also be sure to check any other modules you may have added to the project and their respective gradle and manifest files.

Categories

Resources