Ionic Cordova in Android Studio (no installed buil

2019-01-25 19:50发布

I develop in ionic 2 and I'm trying to open the project (from ionic android build) in Android Studio.

I get the following error:

Error:No installed build tools found. Please install the Android build tools version 19.1.0 or higher.

The problem is the Build Tool is already installed:

enter image description here

I'm using the latest version of cordova with ionic2.

Any thoughts?

2条回答
放荡不羁爱自由
2楼-- · 2019-01-25 20:07

You should refer doFindLatestInstalledBuildTools method in cordova.gradle file:

String doFindLatestInstalledBuildTools(String minBuildToolsVersion) {
    def availableBuildToolsVersions
    try {
        availableBuildToolsVersions = getAvailableBuildTools()
    } catch (e) {
        println "An exception occurred while trying to find the Android build tools."
        throw e
    }
    if (availableBuildToolsVersions.length > 0) {
        def highestBuildToolsVersion = availableBuildToolsVersions[0]
        if (compareVersions(highestBuildToolsVersion, minBuildToolsVersion) < 0) {
            throw new RuntimeException(
                "No usable Android build tools found. Highest installed version is " +
            highestBuildToolsVersion + "; minimum version required is " +
            minBuildToolsVersion + ".")
        }
        highestBuildToolsVersion
    } else {
        throw new RuntimeException(
        "No installed build tools found. Install the Android build tools version " +
            minBuildToolsVersion + " or higher.")
    }
}

Obviosly, getAvailableBuildTools() returns empty array:

String[] getAvailableBuildTools() {
    def buildToolsDir = new File(getAndroidSdkDir(), "build-tools")
    buildToolsDir.list()
        .findAll { it ==~ /[0-9.]+/ }
        .sort { a, b -> compareVersions(b, a) }
}

In my case, System.getenv("ANDROID_HOME") returned wrong path in getAndroidSdkDir() method, so the solutions are:

  1. Simply replace System.getenv("ANDROID_HOME") with your real Android SDK path (but you should remember that SDK location differs on other PCs)
  2. Setup correct path for $ANDROID_HOME environment variable
  3. You can set build tool version manually in build.gradle files and skip calling methods described above (be sure to setup it for all the modules in the app):

    android { buildToolsVersion "your_version_here" }

查看更多
我只想做你的唯一
3楼-- · 2019-01-25 20:09

I had similar issue. I fixed it by changing the Project structure as follows:

  • Gradle version=3.5
  • Android Plugin version=2.3.1
查看更多
登录 后发表回答