Failed to set up SDK: Error:Module 'app': platform 'Google Inc.:Google APIs:21' not found

前端 未结 4 1050
借酒劲吻你
借酒劲吻你 2021-02-14 12:52
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. Attemp

4条回答
  •  长发绾君心
    2021-02-14 13:02

    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.

提交回复
热议问题