【问题标题】:How to configure NDK project in Android Studio 1.3如何在 Android Studio 1.3 中配置 NDK 项目
【发布时间】:2015-10-31 14:27:39
【问题描述】:

我一直在尝试按照this 文章和this 文章为 NDk 配置 Android Studio。以下是我的 gradle-wrapper.properties 的内容

#Sat Aug 08 09:36:53 IST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip

以下是build.gradle(project)的内容

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

最后是 build.gradle(module)

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

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "23.0.0 rc3"

        defaultConfig.with {
            applicationId = "com.opaxlabs.nativetest"
            minSdkVersion.apiLevel =  15
            targetSdkVersion.apiLevel =  22
            versionCode = 1
            versionName = "1.0"
        }
        android.buildTypes {
            release {
                minifyEnabled = false
                proguardFiles += file('proguard-rules.pro')
            }
        }
    }
    android.ndk{
        moduleName = "native"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

当我尝试同步 gradle 文件时,出现以下错误:

Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig

local.properties 中定义了以下路径

ndk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk/ndk-bundle
sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk

所以看起来我错过了一些东西,只是我找不到它。 任何帮助将不胜感激。

【问题讨论】:

    标签: android android-studio android-ndk


    【解决方案1】:
    NDK Build option
    
    ndk {
      moduleName "SeePlusPlus" // Name of C++ module (i.e. libSeePlusPlus)
      cFlags "-std=c++11 -fexceptions" // Add provisions to allow C++11 functionality
      stl "gnustl_shared" // Which STL library to use: gnustl or stlport
    }
    

    【讨论】:

    【解决方案2】:

    在您的 build.gradle(module) 中,android.buildTypes 块需要在 android 块之外。所以它应该是这样的:

    model {
        android {
            compileSdkVersion = 22
            buildToolsVersion = "23.0.0 rc3"
    
            defaultConfig.with {
                applicationId = "com.opaxlabs.nativetest"
                minSdkVersion.apiLevel =  15
                targetSdkVersion.apiLevel =  22
                versionCode = 1
                versionName = "1.0"
            }
        }
        android.buildTypes {
            release {
                minifyEnabled = false
                proguardFiles += file('proguard-rules.pro')
            }
        }
        android.ndk{
            moduleName = "native"
        }
    }
    

    【讨论】:

    【解决方案3】:

    您是否在 Local.property 文件中声明了您的 NDK 路径??

    看起来环境路径和 local.properties 文件指向不同的位置:

    PATH: C:\Program Files (x86)\Android\android-ndk-r9d
    

    local.properties:C:\Program Files (x86)\Android\android-studio\android-ndk-r9d

    确定哪个是正确的。您可以保留 PATH 并删除 local.properties 声明,然后通过控制台尝试此命令:ndk-build -?看看它是否在 PATH 中找到

    【讨论】:

    • 从 Android Studio 1.3 起无需声明 NDK Path。现在设置在Project Structure > SDK Location
    • 切勿对 NDK 使用带空格的路径。如果它的路径也有空格,Android SDK 可能会不高兴。
    猜你喜欢
    • 2017-07-08
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 2015-05-21
    • 2019-02-14
    相关资源
    最近更新 更多