android - 如何在Android Studio 1.3中配置NDK项目

标签 android android-studio android-ndk

我一直在尝试按照 this 为 NDk 配置 Android Studio。文章和this文章。以下是我的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

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

最佳答案

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

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"
    }
}

关于android - 如何在Android Studio 1.3中配置NDK项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31889657/

相关文章:

java - 如何通过 ParseTwitterUtils 创建 TwitterCore TwitterSession

android - 在模块中找到重复的类 com.mapbox.android.telemetry.AlarmReceiver。 Mapbox 安卓工作室

Android Studio 启动时崩溃

java - 需要添加 float 操作按钮错误android中fragment页面中的多个根标签

android - "Cannot Resolve Symbol"使用android时出错 :id= "@+android:id/my_id"

android - 通过 Android 以编程方式发送 Google 表单响应

android - 在 Android 中立即设置通知

c++ - "GL_UNPACK_SWAP_BYTES"未在此范围及其他范围内声明

gcc - 使用 Cmake 构建 Android NDK 项目

android - 链接Android NDK下的共享库