无法获得类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象的未知属性“ ANDROID_SDK_VERSION”

时间:2018-09-13 01:54:07

标签: android ionic3 cordova-plugins

我有以下离子科尔多瓦项目:

/my-app/config.xml

<engine name="android" spec="^6.4.0" />
    <plugin name="cordova-plugin-device" spec="^1.1.7" />
    <plugin name="cordova-plugin-facebook4" spec="^2.4.0">
        <variable name="APP_ID" value="123456789" />
        <variable name="APP_NAME" value="my-app" />
    </plugin>
    <plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.1.0" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="ionic-plugin-keyboard" spec="^2.2.1" />

/my-app/package.json

"cordova": {
        "plugins": {
            "cordova-plugin-facebook4": {
                "APP_ID": "123456789",
                "APP_NAME": "my-app"
            },
            "cordova-plugin-device": {},
            "cordova-plugin-ionic-webview": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {}
        },
        "platforms": [
            "android"
        ]
    }

我跑步时:enter code here离子信息

cli packages: (/usr/lib/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts : 3.1.0
    Cordova Platforms  : android 6.4.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.11.4
    npm  : 5.6.0 
    OS   : Linux 4.15

上下文: 当我运行时:ionic cordova build android

> ionic cordova prepare
> cordova prepare
✔ Running command - done!

> cordova build android
✖ Running command - failed!
[ERROR] An error occurred while running cordova build android (exit code 1):


        ANDROID_HOME=/home/rreyes/android-sdk-linux
        JAVA_HOME=/usr/lib/jvm/java-8-oracle
        Subproject Path: CordovaLib
        The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use 
        Task.doLast(Action) instead.
            at build_8oeka4t56dp9oa43kn5u8er7z.run(/home/rreyes/workspace/tennis-up-app/platforms/android/build.gradle:141)

        FAILURE: Build failed with an exception.

        * Where:
        Build file '/home/rreyes/workspace/tennis-up-app/platforms/android/build.gradle' line: 255

        * What went wrong:
        A problem occurred evaluating root project 'android'.
        > Could not get unknown property 'ANDROID_SDK_VERSION' for object of type 
        org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

        * Get more help at https://help.gradle.org

        BUILD FAILED in 2s
        Error: /home/rreyes/workspace/tennis-up-app/platforms/android/gradlew: Command failed with exit code 1 Error 
        output:
        FAILURE: Build failed with an exception.

        * Where:
        Build file '/home/rreyes/workspace/tennis-up-app/platforms/android/build.gradle' line: 255

        * What went wrong:
        A problem occurred evaluating root project 'android'.
        > Could not get unknown property 'ANDROID_SDK_VERSION' for object of type 
        org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

        * Get more help at https://help.gradle.org

        BUILD FAILED in 2s

我确实为ANDROID_SDK_VESION =“ 4. +”设置了env变量

问题:我需要做什么才能成功运行ionic cordova build android

谢谢。

2 个答案:

答案 0 :(得分:1)

您需要在项目级别的build.gradle文件中设置ANDROID_SDK_VESION变量,或者也可以在gradle.properties文件中对其进行定义。

在项目级别build.gradle

project.ext { variableName = value }

使用以下方式访问它: project.ext.variablename

在gradle.properties文件中 VariableName = value

使用以下方式访问它: $variableName

答案 1 :(得分:0)

该问题主要是由于cordova中的地理位置插件引起的 尝试将其删除并重新安装(最新版本) cordova插件列表提供了所有插件 cordova plugin rm会删除该插件。

setting properties (project.properties) file to the following might resolve the issue:
target=android-27
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.google.android.gms:play-services-base:9.2.1
cordova.system.library.2=com.google.android.gms:play-services-ads:9.2.1
cordova.system.library.3=com.android.support:support-v4:24.1.1+