我尝试将我的Android项目迁移到新的实验性gradle插件。我按照this页面上的说明操作。我对所需文件进行了更改,但是当我尝试使用gradle文件同步项目时出错。
错误:执行模型规则时抛出异常:BaseComponentModelPlugin.Rules #createBinaryTasks
apply plugin: 'com.android.model.application'
def opencv_modules = ["shape", "stitching", "objdetect", "superres", "videostab", "calib3d", "features2d", "highgui", "videoio", "imgcodecs", "video", "photo", "ml", "imgproc", "flann", "core", "hal"]
def opencv_third_parties = [ "liblibjpeg", "liblibpng", "liblibtiff", "liblibwebp", "liblibjasper", "libIlmImf", "libtbb"]
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.company.app"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "0.1"
buildConfigFields.with {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
}
}
android.ndk {
moduleName = "MyModule"
toolchain = "gcc"
toolchainVersion = "4.9"
//toolchain = "clang"
//toolchainVersion = "3.6"
// Note that CFlags has a capital C, which is inconsistent with
// the naming convention of other properties. This is a
// technical limitation that will be resolved
CFlags.add("-DCUSTOM_DEFINE")
cppFlags.add("-DOS_ANDROID")
cppFlags.add("-D__ANDROID__")
cppFlags.add("-DANDROID")
cppFlags.add("-DES2")
cppFlags.add("-DES2")
cppFlags.add("-I"+ project(':MyProject').getProjectDir() + "/../../../third-party/readerwriterqueue")
cppFlags.add("-std=c++14")
cppFlags.add("-fexceptions")
cppFlags.add("-frtti")
cppFlags.add("-fsigned-char")
cppFlags.add("-fPIC")
cppFlags.add("-fvisibility=hidden")
cppFlags.add("-ffunction-sections")
cppFlags.add("-fdata-sections")
ldLibs.add("log")
ldLibs.add("EGL")
ldLibs.add("GLESv2")
ldLibs.add("atomic")
ldLibs.add("z")
ldFlags.add("-Wl,--gc-sections")
stl = "gnustl_shared"
//stl = "stlport_shared" <-- currently no thread header
//stl = "c++_shared" <-- clang
}
android.buildTypes {
debug {
debuggable = true
ndk.with {
debuggable = true
}
}
release {
debuggable = false
minifyEnabled = true
proguardFiles .add(file('proguard-rules.pro'))
ndk.with {
debuggable = false
}
}
}
android.productFlavors {
create("armv7") {
ndk.with {
abiFilters.add("armeabi-v7a")
println "*** building for armv7: " + abiFilters
abiFilters.each { targetAbi ->
opencv_modules.each { module ->
def libPath = project(':MyProject').getProjectDir().absolutePath
libPath += "/../../../third-party/opencv_android/sdk/native/libs/"
libPath += targetAbi
libPath += "/libopencv_"
libPath += module + ".a"
//println libPath
ldLibs.add(libPath)
}
opencv_third_parties.each { module ->
def libPath = project(':MyProject').getProjectDir().absolutePath
libPath += "/../../../third-party/opencv_android/sdk/native/3rdparty/libs/"
libPath += targetAbi
libPath += "/"
libPath += module + ".a"
//println libPath
ldLibs.add(libPath)
}
}
}
}
}
// You can modify the NDK configuration for each variant.
components.android {
binaries.afterEach { binary ->
binary.mergedNdkConfig.cppFlags.add(
"-DVARIANT=\"" + binary.name + "\"")
}
}
// Configures source set directory.
android.sources {
test {
java {
source {
srcDirs += 'src/test/java'
}
}
assets {
source {
srcDirs += '../../../assets/'
}
}
}
androidTest {
java {
source {
srcDirs += 'src/instrumentTest/java'
}
}
res {
source {
srcDirs += 'src/instrumentTest/res'
}
}
}
main {
java {
source {
srcDirs += 'src/main/java'
srcDirs += '../../../third-party/assetbridge/src/'
}
}
assets {
source {
srcDirs += '../../../assets/'
}
}
jni {
source {
srcDirs += '../../../third-party/assetbridge/jni/'
srcDirs += '../../../lib/'
exclude '**/*Test*'
srcDirs += '../../common/'
srcDirs += 'src/main/jni'
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// Set this dependency if you want to use Mockito
//testCompile 'org.mockito:mockito-core:1.10.19'
// Set this dependency if you want to use Hamcrest matching
testCompile 'org.hamcrest:hamcrest-library:1.3'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}