103

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: enter image description here

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139

20 Answers20

80

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

htafoya
  • 18,261
  • 11
  • 80
  • 104
21

In Android Studio File -> Invalidate Caches/Restart solved the issue for me.

Mohammed Ali
  • 2,758
  • 5
  • 23
  • 41
17

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.

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
12

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.

enter image description here

Hans Knöchel
  • 11,422
  • 8
  • 28
  • 49
Radmation
  • 1,486
  • 1
  • 13
  • 30
5

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.

enter image description here

  1. Go to Project Structure
  2. Select App Module
  3. 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)
  4. Press OK
  5. 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:

  1. 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)
  2. Press Ok and wait for completion of on going process
  3. Revert back your build tool version to what it was before you changed
  4. Press Ok
  5. Wait for the completion of process.
  6. Done!
Sagar Patel
  • 506
  • 1
  • 8
  • 23
3

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)

Geremy
  • 2,415
  • 1
  • 23
  • 27
3

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)

Scott Barbour
  • 374
  • 3
  • 14
3

Had the same issue with another number, this worked for me:

  1. Click the error message at top "Gradle project sync failed" where the text says ´Open message view´

  2. In the "Message Gradle Sync" window on the bottom left corner, click the provided solution "Install missing ... "

  3. 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 Android SDK providing a solution in the bottom left corner

ViktorMS
  • 1,112
  • 10
  • 25
  • Please add more information in the case where your image link disappears, so that others may follow the answer even once the link dies. – Dessus Jan 30 '18 at 23:25
3

For me the problem was in that I wrote compileSdkVersion '23' instead of 23. The quotes were the problem.

konnovdev
  • 823
  • 8
  • 16
2

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

Akshat Gupta
  • 1,904
  • 2
  • 14
  • 13
2

This poblem is solved for me after Run as administrator the Andorid Studio

PurTahan
  • 789
  • 8
  • 24
1

Open the Android SDK Manager and Update with latest.

Biswajit Karmakar
  • 9,799
  • 4
  • 39
  • 41
1

Nothing worked for me. I changed SDK path to new SDK location and reinstalled SDK.Its working perfectly.

user1035292
  • 1,378
  • 12
  • 14
1

Tools > Android > SDK Manager.

enter image description here

CoolMind
  • 26,736
  • 15
  • 188
  • 224
1

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.

user3288482
  • 49
  • 1
  • 2
1

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.

Neo42
  • 642
  • 3
  • 10
  • 31
1

Download the specific Android release from the link specified in the build console.

KayV
  • 12,987
  • 11
  • 98
  • 148
0

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

Kose
  • 37
  • 9
0

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

Stephen J
  • 2,367
  • 2
  • 25
  • 31
0

AndroidSDK > SDK platforms > and install API Level 23

bash-tag
  • 1
  • 1
  • can you please explain your answer further? – Matias Chara Oct 12 '20 at 13:59
  • what I mean open android studio at the top right hand side click on android SDK Manager and it will show availalable API levels there , look for API level 23 select and click apply – bash-tag Nov 02 '20 at 11:07