Android SDK compact - android

I am using Android 23 build tools,but my imported project support only android 19,how to compact with this or how to fix it.
I see the followinf error in logcat,
"Failed to sync Gradle project 'My Application1'
Error:Error:Cause: failed to find target with hash string 'android-19' in: E:\Android\android-sdk_r24.4.1-windows\android-sdk-windows
Open Android SDK Manager"
This is my build.gradle file"
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
allprojects {
repositories {
jcenter()
}
}
This is my module/build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.appsrox.remindme"
minSdkVersion 7
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

Error:Error:Cause: failed to find target with hash string 'android-19'
It happens when the Android-19 sdk is not installed.
Open your SDK Manager and check to see if Android 4.4 (API 19) is installed.
Pay attention using the latest support libraries. The v23.x.x require compileSdk 23
About :
my imported project support only android 19
you should check the difference between compileSdkVersion, minSdkVersion, and targetSdkVersion.
compileSdkVersion is your way to tell Gradle what version of the Android SDK to compile your app with. Using the new Android SDK is a requirement to use any of the new APIs added in that level.
minSdkVersion is the lower bound for your app. The minSdkVersion is one of the signals the Google Play Store uses to determine which of a user’s devices an app can be installed on.
targetSdkVersion is the main way Android provides forward compatibility by not applying behavior changes unless the targetSdkVersion is updated
More info here.

Related

Is Android Studio backward compatible with older API? (specifically, need to target older API (27) with Android Studio 3.6.3 )

Is Android Studio backward compatible with older API?
More specifically,
I need to target API 27 with Android Studio 3.6.3.
I am unable to do so. Why?
Note: I am aware that I would not be able to publish to Play Store. This is not a problem for me.
As stated here - https://developer.android.com/studio/releases/gradle-plugin
Although the Android plugin is typically updated in lock-step with
Android Studio, the plugin (and the rest of the Gradle system) can run
independent of Android Studio and be updated separately.
And in Upgrade Gradle section, in the table
Plugin Version 3.2.0 - 3.2.1 works with Gradle version 4.6+
My set up:
Settings.gradle
distributionUrl=https://services.gradle.org/distributions/gradle-4.9-bin.zip
In apps build.grade:
SDKs/Build tools are set as:
compileSdkVersion 27 buildToolsVersion "27.0.2"
minSdkVersion 27 targetSdkVersion 27
And Dependencies:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'com.android.support:appcompat-v7:27.1.0' i
implementation 'com.android.support:design:27.1.0'
Build.gradle (project)
buildscript {
ext.kotlin_version = '1.3.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
But I get the following:
The specified Android SDK Build Tools version (27.0.2) is ignored, as
it is below the minimum supported version (28.0.3) for Android Gradle
Plugin 3.2.1.
Why is that? Surely I was able to target 27 with that plug in version in older versions of AS.
And when I build:
error: failed linking references. (No additional detail in logs)
Note: Trying with even lower versions of Build Tools and Android Gradle Plug Ins (and targeting lower api) gives the same error. Downgrading the gradle version doesn't work either (tried with 4.6)
Note 2: Trying with the latest versions (accepting what AS 3.6.3 gives you by default, which is gradle-5.6.4, buildToolsVersion "29.0.2") gives the below error.
This is easy to reproduce - just create a new project (choose empty activity to reduce dependencies), use legacy support libraries, and change compile and target SDK to 27
.../appcompat-v7-28.0.0/res/values-v28/values-v28.xml:5:5-8:13: AAPT:
error: resource android:attr/dialogCornerRadius not found.
Does it mean you just cannot target anything below 28 with AS 3.6.3? What role would AS play here if the building blocks here are Build Tools and Android Gradle Plug in (as stated above), which I can choose as I please, and yet to no effect?
And just want to note: no, I don't want to update to api 28. I need specifically below 28, and my current version of AS is 3.6.3.
Is there no way out and have to use an older AS? And if the latter, what would then be the role of AS in this?
Tool versions are largely independent of your targetSdkVersion, you don't need buildToolsVersion "27.0.2" for a target sdk of 27
Edit your app's build.gradle to use modern versions of the build tools, and then set targetSdkVersion 27
Note that you will not be able to deploy to the Play Store with this as the minimum target is now 28 (current as of 5/13/2020) source: https://developer.android.com/distribute/best-practices/develop/target-sdk
The following is a portion of a valid app module build.gradle targeting sdk 27
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.mikedg.dekudeals"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
The following is a portion of the buildscript from the project build.gradle that works with it
buildscript {
ext.kotlin_version = '1.3.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
If the above does not work, I recommend looking into migrating to the androidx libraries instead of the old support libraries. https://developer.android.com/jetpack/androidx/migrate#additional_resources
I don't think this should cause problems, but can't confidently say that it wouldn't

gradle file config to target android API 22

I have installed Android Studio 3.1.13 with gradle 4.8.1 and java 1.8.0_171, previously installed. I have installed also the SDK API 22 because I need to test an app in Android 5.1.1
The problem is that the default configuration has compileSdkVersion 28 and I had changed it to 22. I have tried many settings but there are always errors due to the version of android API
My current module build.gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.company.test"
minSdkVersion 22
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
}
and the proyect build.gradle is
buildscript {
repositories {
google()
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When I tried to build, the IDE now says
The SDK Build Tools revision (22.0.1) is too low for project ':app'. Minimum required is 25.0.0
Don't know how can I build and test and app for API 22. I'm newbie in Android develpoment. Thanks in advance
As far as I understand your question, the app needs to be tested running on android api level 22 right?
Based on this assumption I would say the most straight forward solution would be to keep every value on default (as long as this worked for you before). Just lower the minSdkVersion to 22.
Short explanation of most important values:
compileSdkVersion 22 : API Level the app is compiled against
buildToolsVersion '22.0.1' : Buildtools Version to compile code (has to match compileSdkVersion)
minSdkVersion 22 : This is the minimum api you want the app running on.
targetSdkVersion 22 : Simply says, you tested your app running on specified API. Google now uses this to determine if your app is up to date to be published in Playstore or not
As emandt already mentioned BUILDTOOLS and gradle should be up to date, as well as targetSdkVersion and compileVersion.
TESTING APP ON API Level:
As long as you compiled your app for a target higher than minSdk you can simply build and install the apk to a device running the requested API level.
The "buildToolsVersion" string should be compatible with the "classpath 'com.android.tools.build:gradle:x:x:x" setting.
You have to lower the second setting until it is accepted.
However I suggest to use latest BUILD TOOLS and latest GRADLE and not revert back to an old ones. Those Tools affect only the Build procedure, not the App itself.

Gradle failed to sync with 'unable to find optional library'

I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:
Warning: Unable to find optional library: org.apache.http.legacy
My project gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And my module gradle:
apply plugin: 'android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
From the google docs:
To continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.
How can I fix this?
Edit: Things I've tried so far:
Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.
Change the compileSdkVersion and targetSdkVersion to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.
Top level build.gradle - /build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
Module specific build.gradle - /app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
Add org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to app/libs directory and sync your project
After a lot of working this solutions work for me
.
** Studio\Android\sdk\platforms** here delete your android-23 and from sdk manager update api 23 again.**
.
it will solve your issue.
In my case, it didn't work because I was missing optional.json in <sdk-path>\platforms\android-23\optional\, directory with the following content:
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Creating a new JSON file with with above content solved the problem for me.
You need to add org.apache.http.legacy.jar jar file in your Android Stuido project's app/libs folder.
Jar Location - `<SDK LOCATION>\android-sdk\platforms\android-23\optional`
To do this, just right click on your project and select Show in Explorer then go to ...\app\libs and paste above jar file and Sync your Project with Gradle File
Module:app
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "<ur_app_id>"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Update your project gradle file to use gradle version 1.3.1.
classpath 'com.android.tools.build:gradle:1.3.1'
Also try adding codehause repo.
repositories {
mavenCentral()
maven{
url 'http://repository.codehaus.org'
}
}
In my case the problem was actually occurring because I didn't have the correct SDK installed on that computer. Navigating to .../Android/Sdk/platforms/android-23 I could see that folder was empty. Adding SDK 23 via the SDK manager fixed the problem and allowed me to compile.
You should manually check that you have the same version of the SDK installed that is specified under compileSdkVersion in your build.gradle file.
To save time 2 solutions are best and works for me.
Solution 1 :
open your android sdk manager and reinstall API 23 (remove and install again).
Solution 2 :
Download this file which contain optional.json file
extract and move optional.json to :
C:\Users\\AppData\Local\Android\sdk\platforms\android-23\optional
if above solution is not work then try this way
I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.
Relocate your Project and the build will succeed.
Copy "sdk\platforms\android-23\optional\org.apache.http.legacy.jar" to your app module libs directory, then add as library;
If you enable the proguard, please edit "proguard-rules.pro" to keep related classes or exception will occurred.

Gradle code not building: aidl is missing

I updated android studio from version 1.0 to 1.2.1 and when I started my first application the this appears.
Error:Execution failed for task ':app:compileDebugAidl'.
aidl is missing
I have made sure that all sdk are up to date. This is my gradle build code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc1"
defaultConfig {
applicationId "com.example.william.myapplication"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
compileSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
}
It seems that AndroidStudio-1.3-Preview is using an unexpected version of the gradle plugin. (at least when you create a fresh new project)
Similarly, if you open an existing project using:
an older version of the plugin. (<1.3.0-beta1)
latest build tools (23.0.0-rc1)
compileSDK 22
---> you will probably have this strange error : "aidl is missing" (even in projects not using aidl !)
Solution:
Be sure to use the latest android-gradle-plugin (in the root build.gradle) :
classpath 'com.android.tools.build:gradle:1.3.0-beta1'
under buildscript-->dependencies.
Example :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
and the latest build tools (in module build.gradle):
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc1"
... }
BE AWARE that with this config you are using the latest build tools -not released yet- and the preview of Android-M ---> things can be unstable
I had the same error. I changed the build tools version in the gradle script to my actual sdk build tool version found in sdk manager and that did the trick.
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
...

Why isn't Android Support Library version 22 available?

Today I noticed that Android API 22 is available so I changed target SDK of my app to 22. When I did that, Gradle started complaining that support libraries cannot have versions lower than the target SDK version.
I checked Support Library revisions link and it does show that version 22 of "v4 support library" and "v7 appcompat library" have been released. So, I bumped up their versions as well in build.gradle file. Gradle then suggested that I install the "Android Support Repository". I had it installed, but I installed it again; and Gradle continued to complain. When I checked ${android_home}/extras/android/m2repository/support-v4 it indeed did not have the version 22.0.0 folder.
I also directly opened the link https://dl.google.com/android/repository/addon.xml which was used by Support Repository installer and it indeed does not list version 22 libraries!
What is wrong here?
After reading your question and the comments again, I understand what you are trying to say. Currently the SDK Manager does not have the Support v22 out.
You CAN download API 22 but you are NOT seeing support-v4. By the way, "${android_home}/extras/android/m2repository/support-v4" is the wrong directory.
The correct directory is: "${android_home}/extras/android/m2repository/com/android/support/support-v4".
Also, you must have it downloaded from your build.gradle, for example:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22 // <-- You need this
buildToolsVersion '22.0.0' // <-- You need this
defaultConfig {
applicationId 'burrows.apps.example.admob'
minSdkVersion 9
targetSdkVersion 22 // <-- You need this
versionCode 1
versionName '1.0'
}
signingConfigs {
debug {
storeFile rootProject.file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dexOptions {
preDexLibraries = Boolean.valueOf(System.getProperty("pre-dex", "true"))
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':Lib-BurrowsApps')
compile 'com.android.support:support-v4:22.0.0' // <-- You need this
compile 'com.google.android.gms:play-services-ads:6.5.87'
}
Source: https://github.com/jaredsburrows/BurrowsAppsExamples/blob/master/Lib-BurrowsApps/build.gradle
Google's m2repository works just like the normal ~/.m2/repository/.
To get the most recent version of the Android support library, I was able to do the following:
Install all the latest things in the SDK Manager
Check what the latest revision is (22.1.0 at the time of this writing)
Update the dependencies section of build.gradle accordingly
build.gradle
dependencies {
...
compile 'com.android.support:support-v4:22.1.+'
}
See also (documentation)
Support Library
Support Library Setup
Support Library Features

Categories

Resources