I have this repository ( https://github.com/udacity/Just-Java/tree/Lesson_2 ) that I'm trying to import. I extract the folder from the zip file that I downloaded from there. Then I try to use "import project" function on Android Studio, but I am not sure which exact folder/directory to select for import. When I use the main directory I unzipped, it takes about half an hour to load it and then gives me an error saying "failed to find target with hash string 'android-24' in: [i]my appdata folder[/i]
I have very slow connection at the moment, so it takes ages to download this Android SDK Platrom 24. I am running the latest version of the Android Studio.
So the 'build.gradle' file (Assuming you are using gradle) would specify which is the target Android SDK.
Now I suppose you have some Android SDK and the corresponding build tools already installed. These would then not require a download. But then gradle requires an internet connection to actually search for libraries that it should download to satisfy the dependencies of the project.
Now once you have figured out which Android SDK and build tools you have, you can make the change in the build.gradle file. (This would be in the /app/). You would have to make an edit here.
compileSdkVersion 21 *replace with the version you have*
buildToolsVersion "21.1.2" *this should also start with the compileSdkVersion number*
Hope this helps!
This is your app module build.gradle file, change in this file according to what you have in your SDK.
apply plugin: 'com.android.application'
android {
compileSdkVersion 24 // Change what SDK Version you have
buildToolsVersion "24.0.2" // Change buildTool Version
defaultConfig {
applicationId "com.example.android.justjava"
minSdkVersion 15
targetSdkVersion 24 // Change targetSDK, can be same as compileSdk
versionCode 1
versionName "1.0"
}
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:24.2.0' //Change appcompact version
}
Related
I'm very new at Android app development and trying to apply some changes on an existing project. When I try to change the Compile Sdk Version in Project Structure in Android Studio, it displays a red warning (Invalid hash string) on the right side of the chosen Sdk "Vuzix Corporation:Vuzix M300 SDK:23" and doesn't apply the changes. And then I realised the same also happens for "Google Inc.:Google APIs:23".
It's an app built for Vuzix M300 augmented reality glasses and I followed the documentation on their site to update an existing project and install the M300 SDK in Android Studio. First I built the app using the standard Sdk with Compile Sdk Version API 23: Android 6.0 (Marshmallow), as they recommended to do so. Later they want us to change the Compile Sdk Version to Vuzix M300 SDK (API 23) in Project Structure, which didn't work.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "de.tum.fml.pbvofflineapp"
minSdkVersion 15
targetSdkVersion 15
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
I expect that the compileSdkVersion should change but I don't know what it should be for that specific Sdk.
your compileSdkVersion , targetSdkVersion and buildToolsVersion should be on the same version level .
also , in the SDK Manager, make sure SDK version is installed.
after that run "invalidate caches/restart" if the problem persist
Edit
if you are using gradle plugin version 3.4.1
This version of the Android plugin requires the following:
SDK Build Tools 28.0.3 or higher.
source
which means you can't use compileSdkVersion 23
If you change compileSdkVersion change also targetSdkVersion to the same. It has no sense to target a previous sdk and compile with greater one. Also you should have buildToolsVersion according with compile sdk
If you not choose your desired Compile Sdk Version as "Vuzix Corporation:Vuzix M300 SDK:23".
which will leads to can not find custom add-on sdk class build error.
I have imported a android source code from Github and while syncing the gradle process I have got an error
Error:(1, 0) Plugin with id 'com.android.application' not found.
Open File
This is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "activities.safepassbeta"
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
}
Try changing the classpath in the top level build.gradle file to 'com.android.tools.build:gradle:2.0.0-beta7' and the distributionUrl value in gradle-wrapper.properties file to https://services.gradle.org/distributions/gradle-2.10-all.zip.
Make sure that in the settings for gradle in the 'Build, execution and deployment' section, you have set the preference to 'Use default gradle wrapper'.
As the other answer described, try changing the classpath in the top level build.gradle file. The file you show is the application build.gradle, not the top level build.gradle file. For Android Studio 3, you can try using 'com.android.tools.build:gradle:3.0.1'. The problem is that the gradle dependency is not downloading properly, usually because of improper settings for the url to use to download gradle. This is a common problem. If the problem persists look into solutions for how to set up gradle, such as Manually install Gradle and use it in Android Studio
A quick-and-easy fix is to look at your previous projects which work on your IDE, look at what version of gradle they are using. If you use that version of gradle in this project it will most likely work.
However, the 'proper' solution is to set up the distributionUrl properly. Worst come to worst, if that does not work, you could also try manually downloading Gradle to use it in your project.
I have the above error and have no clue why I still have it. I have reinstalled API 23 numerous times and done googling and the only fix I found was to reinstall the API but still have the issue.
Does anyone have a fix for it?
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.example.app"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
lintOptions {
disable 'InvalidPackage'
}
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:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'me.neavo:volley:2014.12.09'
compile 'com.google.code.gson:gson:2.5'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.android.support:support-v4:23.1.1'
}
Try to use compileSdkVersion 23 instead of compileSdkVersion 'Google Inc.:Google APIs:23'
I got this error when trying to build a project on Windows that was originally built on Ubuntu. If you're not sure which build.gradle file is causing it and the project has multiple modules, do a project search for "compileSdkVersion."
Windows expects: compileSdkVersion 'Google Apis:Google Apis:23'
Ubuntu expects: compileSdkVersion "Google Inc.:Google APIs:23"
Main module or any library must be using 'Google Inc.:Google APIs:23' which is not installed in SDK. So try to change it and compile
Change : compileSdkVersion 'Google Apis:Google Apis:23'
To : compileSdkVersion 23 (You should have android-23 installed in SDK)
I got this error too, when i imported eclipse project to android studio.
So i just did a little search "Edit -> Find -> Find in path" for "APIs 23" And i did replace (compileSdkVersion 'Google Inc.:Google APIs:23') in "Build.gradle" withe (compileSdkVersion 24).
I think it should works.
Good luck
Error:Cause: failed to find target with hash string 'Google Inc.:Google APIs:17' in: C:\Users\brahmaiah\AppData\Local\Android\Sdk
Open Android SDK Manager</a>
when i have been importing the proj of eclipse into android adt i faced same problem.but i rectrify throug the following content changing which is in gradle.build file.i.e. {
compileSdkVersion 23
targetsdkVersion"23.0.1".}
You can create a new project and see what's written in this project's 'build.gradle'.For example it is 'compileSdkVersion 25',then change your target project to 'compileSdkVersion 23'.
I am using Ubuntu ,and I had the same issue. The accepted answer did not work for my version of Android Studio (2.3.3).
I had to import an Eclipse webapp project for Android SDK 15, and did receive the same message. The solution that worked for me was the following:
Download the correct version of the Android SDK (version 15 in my case)
Use the name of the directory folder (in my case "android-15" stored in my home folder at "~/[user_xxx]/Android/Sdk/platforms/".
Edit the line in the gradle script in my case to :
compileSdkVersion 'android-15'
Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found.
At a complete loss as to why this isn't working. Attempted to update my SDK to 23 but realized I wasn't prepared to deal with all the new deprecations, etc., so I reverted to an older version on Mercurial. I've done literally nothing else, and the reversion should have solved everything. Unfortunately, I'm stuck unable to connect my app and build it. I've even reinstalled Android Studio from scratch, but I continue to receive the same warning and my app won't build at all. What could possibly be going wrong?
Here is my build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.elgami.customizer"
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.ogaclejapan.smarttablayout:library:1.5.0#aar'
compile 'com.github.antonyt:InfiniteViewPager:v1.0.0'
compile 'com.android.support:appcompat-v7:22.2.0'
// recyclerview
compile 'com.android.support:recyclerview-v7:23.1.1'
// google analytics
compile 'com.google.android.gms:play-services-analytics:8.3.0'
// pager sliding strip
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
// http library (for using beanstream REST)
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
// amaazon S3 uploads
compile 'com.amazonaws:aws-android-sdk-s3:2.1.+'
// paypal purchasing
compile files('libs/PayPalAndroidSDK-2.7.1.jar')
// Module dependency on ParseLoginUI library sources
compile project(':ParseLoginUI')
// Parse libs
compile files('libs/ParseCrashReporting-1.9.2.jar')
compile files('libs/Parse-1.9.1.jar')
compile files('libs/ParseFacebookUtilsV4-1.9.1.jar')
// android support v4
compile files('libs/android-support-v4.jar')
// facebook SDK
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
//butterknife
compile 'com.jakewharton:butterknife:6.1.0'
// Subsampling-scale-image-view (for templating)
//compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.1.4'
compile files('libs/AppRater.jar')
}
You can use compileSdkVersion 21 instead of yours .
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.elgami.customizer"
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
The (currently accepted) answer that suggest replacing Google Inc.:Google APIs:21 with 21 is NOT suitable if you have some legacy app still using Google Map v1 (for example).
If you are in this situation you REALLY need to compile against Google Inc.:Google APIs:21 or 23 etc...
The solution here is to
Step 1
Open the old SDK manager interface clicking the Launch Standalone SDK Manager link below the Android Studio SDK Manager or by executing ${ANDROID_SDK_DIR}/tools/android sdk from command line to open it directly.
Then locate Google APIs for the SDK version you need and install it:
That package is hidden, for some reason, inside Android Studio and I expect Google will remove it at some point. Currently the SDK 24 one (Marshmallow) is available but the 25 (Nougat) is not, they may add it in the future, or not. We will have to wait and see.
If you are in this situation and Google decide to stop providing it you'll have to rewrite the functionality using maps v2.
Step 2
Even after doing this and cleaning + gradle resync you'll get this error From Android Studio:
Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
But it will compile if you try to do it from the command line (./gradlew assembleDebug).
The reason has apparently something to do with the Android Studio embedded Java JRE.
To make it compile inside Android Studio open the Project Structure from Android Studio and provide a custom path for a JDK you installed on your system (you must install a OpenJDK / OracleJDK on your computer).
NOTE: it may be needed to navigate to the location instead of copying the path for Android studio to take the change. Do not pick the jre directory, pick the JDK (folder containing jre).
WARNING: this change is not specific to the project but will be applied to Android Studio itself and used on any other project.
When it failed for me I downloaded Google API's, just as #Daniel Segato explains, which is the right thing to do, and still I got the message once and again and again.
Until I did this. I opened the module's settings (Ctrl + Alt + Shift + S or File > Project Structure) and, for my module, I changed the Compile Sdk Version option to any other from the list. I resynchornized gradle and then changed the option back to Google APIs (API 23). And then it worked! It's really really really nasty of Android Studio not to recognize the SDK until you change it in that dialog box. But this only happened to me once. Other times it was enough just to download the proper Google API and there you go! But this is nasty.
my problem was in my build.gradle ! when I opened It was like this :
android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.pixelnx.sam.allinone_room"
minSdkVersion 21
targetSdkVersion 21
How fixed it ?!
remove 'Google Inc.:Google APIs:21' and write 29 instead of it
2.set 29 for targetSdkVersion
RESULT :
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.pixelnx.sam.allinone_room"
minSdkVersion 21
targetSdkVersion 29
Background
On Android Marshmallow, Google has completely removed the support of Apache HTTP client (link here) because it doesn't have good performance compared to the alternatives.
This might also be the cause for so many apps crashing on Android Marshmallow.
The problem
Google allows you to still use this API, just not as a built in one, by adding this line to the gradle file:
useLibrary 'org.apache.http.legacy'
So, this is what I did:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
And:
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.user.androidmtest"
minSdkVersion 'MNC'
targetSdkVersion 'MNC'
versionCode 1
versionName "1.0"
}
When I tried it, it compiled fine (no errors being shown, and I could run the proof-of-concept app, as it doesn't have any special code), but when I tried using some of the classes that I know that are part of the old API (like "HttpClient" class), I see that it doesn't allow me to do so.
I know it's not recommended to use this solution, but we must have the app ready to work there at least temporarily, till we work 100% on all of the things that should change for Android Marshmallow, and we don't want surprises in the form of crashes.
Here's a screenshot:
The question
Why does it occur? Did I use it correctly?
EDIT: reported about this issue here:
https://code.google.com/p/android/issues/detail?id=181474
Android Studio was complaining that org.apache.http classes like
org.apache.http.NameValuePair
org.apache.http.client.utils.URLEncodedUtils
were missing.
So I added org.apache.http.legacy.jar which is in
Android/Sdk/platforms/android-23/optional folder to to app/libs
I also added this line to my app.gradle file
compile files('libs/org.apache.http.legacy.jar')
But if you're using more libraries, you can use this way
compile fileTree(dir: 'libs', include: ['*.jar'])
This resolved all my errors that were caused because google removed support of Apache HTTP client.
useLibrary 'org.apache.http.legacy' did not work for me until I upgraded the Gradle tools version in my main build.gradle file of my Android Studio project, as follows:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
Perfect solution here by running a simple file path check.
by running
android {
compileSdkVersion 'android-MNC'
buildToolsVersion "23.0.0 rc3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.user.androidmtest"
minSdkVersion 'MNC'
targetSdkVersion 'MNC'
versionCode 1
versionName "1.0"
}
getBootClasspath().each{File file ->
println file.absolutePath
}
}
}
You will get something like below
/Users/"yourname"/Development/android-sdk-macosx/platforms/android-MNC/android.jar
/Users/"yourname"/Development/android-sdk-macosx/platforms/android-MNC/optional/org.apache.http.legacy.jar
So there you go, the jar is there.For some reason it didn't get added to the project. but you can always add it manually I guess.
The answer above just helps the debug builds to run, and release builds that are utilizing gradle.
Insert this inside the application tag on the manifest file, on all project instances that uses the legacy apache classes:
<uses-library android:name="org.apache.http.legacy" android:required="false" />
This helps for those who are still using Eclipse and ant scripts during compile.
After many frustrating hours, the following worked:
1. Locate the apache jar.
It should reside somewhere like:
C:\Users\<yourname>\AppData\Local\Android\sdk\platforms\android-23\optional
2. Copy org.apache.http.legacy.jar to your libs folder.
Either right click on libs -> paste , or use your file explorer to navigate to the libs folder of your project and paste.
If you don't have a libs folder, as I did, make a new project and import all relevant files into their respective places.
3. Click ok
see this
4. Most important step: Right click on the apache folder and select Add As Library.
see this
Hope this helps someone get on with their life.
I know this is silly reason but at list try it...
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.Hope this work for you.
Legacy Apache library located in
[ANDROID_SDK]\platforms\android-23\optional\org.apache.http.legacy.jar
So you can copy it inside you project libs or just use
compile files("${android.getSdkDirectory().getAbsolutePath()}" + File.separator + "platforms" + File.separator + "android-23" + File.separator + "optional" + File.separator + "org.apache.http.legacy.jar")
in your /app/build.gradle
First you have to check that in your libs folder
Then add into your gradle file like this
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "info.tranetech.laundry"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1
compile 'com.android.support:design:23.0.1
testCompile 'junit:junit:4.12'
compile files('libs/android-async-http-1.4.4.jar')
compile 'com.google.android.gms:play-services:8.4.0'
}
Enable this in sdk/platforms/android-23/optional/optional.json
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Remove
useLibrary 'org.apache.http.legacy'
from the build.gradle and I also added this line to my app.gradle file
compile files('libs/org.apache.http.legacy.jar')
But if you're using more libraries, you can use this way
compile fileTree(dir: 'libs', include: ['*.jar'])
CoPLaS answer fixed my problems.
How to use the legacy Apache HTTP client on Android Marshmallow?
To continue using Apache HTTP classes for API 23+:
First of all, be sure to add the gradle dependencie into the build.gradle f
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
Then add the reference inside build.gradle of your project:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
A simple way to solve this issue is C:\Users\username\AppData\Local\Android\sdk\platforms. Here delete your android-23 and from SDK manager update your API 23 again. It will solve your issue.