user2219372
user2219372

Reputation: 2455

Can't compile NDK android project

I am using android studio and openning the hello-jni sample project. However when I trying to compile the project,it prompts:

Error:Cause: failed to find target with hash string 'android-23' in: 

/Users/xx/opensource/android-sdk-macosx
<a href="openAndroidSdkManager">Open Android SDK Manager</a>

I had installed the android 6.0 (api 23).Why still prompts failed to find? I looked up in the preference in android stuido ,in android SDK tab it seems android 6.0 (api level 23 revision 1) can be found.

Belows is my gradle file:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.0"

        defaultConfig.with {
            applicationId = "com.example.hellojni"
            minSdkVersion.apiLevel      = 3
            targetSdkVersion.apiLevel = 23
        }
    }
    /*
     * native build settings
     */
    android.ndk {
        moduleName = "hello-jni"
        /*
         * Other ndk flags configurable here are
         * cppFlags += "-fno-rtti"
         * cppFlags += "-fno-exceptions"
         * ldLibs    = ["android", "log"]
         * stl       = "system"
         */
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters += "armeabi"
        }
        create("arm7") {
            ndk.abiFilters += "armeabi-v7a"
        }
        create("arm8") {
            ndk.abiFilters += "arm64-v8a"
        }
        create("x86") {
            ndk.abiFilters += "x86"
        }
        create("x86-64") {
            ndk.abiFilters += "x86_64"
        }
        create("mips") {
            ndk.abiFilters += "mips"
        }
        create("mips-64") {
            ndk.abiFilters += "mips64"
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
}

android sdk

Upvotes: 1

Views: 2502

Answers (2)

S. Ramzy
S. Ramzy

Reputation: 26

This worked for me:

  • I removed the application I was working on in home directory under AndroidStudioProjects

  • Restarted Android Studio

  • It prompt the Android Studio Wizard, I went through the Android Studio Setup Wizard where it downloaded some SDK Build-tools for revision 23.0.1.
  • I also clicked on update link when the "Platform and Plugin Updates" message show up while downloading Android SDK Build-tools, to update some components.
  • "Welcome to Android Studio" in the Android Setup Wizard will show up, click on Configure, it will show the Android SDK Manager fetching some packages as shown in the previous answer, click on new or updates links
  • Once the packages are done loading you can go ahead and Install the available packages. After installing the default selected packages you may get more that are selected. Install Android SDK License. You should select each one and then click on accept license. Android Studio will the go through a gradle build process

Upvotes: 1

turkenh
turkenh

Reputation: 2584

I just encountered same problem and I think it is a bug. But I managed to make it work with the following workaround:

  1. First be sure you both install the api and also build-tools (see figure below)

  2. Than in build.gradle, change versions for api and build tools to previous ones: i.e.

        android{ compileSdkVersion = 22
        buildToolsVersion = "22.0.1"    
        defaultConfig.with {
            applicationId = "com.sample.teapot"
            minSdkVersion.apiLevel = 11
            targetSdkVersion.apiLevel = 22
        }
    

    }

  3. Sync gradle successfully

  4. Change versions back

I also restarted android studio several times but not sure whether it is required or not.

Don't Forget to install Android SDK Build-tools

Upvotes: 1

Related Questions