I have just updated my Android Studio setup to 1.3 (latest stable as of 31st of August 2015) and I need to use the latest NDK integration. My previous Android Studio version was 1.2.1 (stable as well).
Following Google Migration to Gradle Experimental Guide I managed to easily adapt my various gradle scripts.
However, Gradle Sync fails with the following error :
Error:No such property: android for class: com.android.build.gradle.managed.ProductFlavor
[Update 1 -> see below, error updated]
When I attempt to Make
the project, I obtain a little more detailed error :
Error:(17, 1) A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> No such property: android for class: com.android.build.gradle.managed.ProductFlavor
App refers to the main application code (with activities and other).
Using the feature F4 > Jumping to Source
, it opens my build.gradle
script from my app
project.
This is the content of the aforementioned script :
apply plugin: 'com.android.model.application' // experimental
model {
android {
compileSdkVersion = 21
buildToolsVersion = '22.0.1'
defaultConfig.with {
applicationId = "company.com.myapplication"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 21
versionCode = 1
versionName = "1.0"
// NDK
android.ndk {
moduleName = "MyAwesomeJNILib"
cFlags "-std=c99"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("arm8") {
ndk.abiFilters += "arm64-v8a"
}
create("x86") {
ndk.abiFilters += "x86"
}
create("x86-64") {
ndk.abiFilters += "x86_64"
}
create("mips") {
ndk.abiFilters += "mips"
}
create("mips-64") {
ndk.abiFilters += "mips64"
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp-android-support:2.4.0'
compile project(':bluetoothmanager')
compile 'joda-time:joda-time:2.8.1'
// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental
}
As you can see, there is nothing very fancy here. But you might notice there is some unit testing setup :
// Units Testing
//androidTestCompile 'junit:junit:4.12'
compile 'junit:junit:4.12' // experimental
androidTestCompile
could not be resolved while migrating to GradleExperimental so I modified following a solution I can no longer find (sorry) where I would simple put compile
in stead of androidTestCompile
.
This was the error :
Error:(71, 0) Gradle DSL method not found: 'androidTestCompile()'
I tried to compare one of Google's NDK sample (hello-jini
for example) as provided in the aforemention guide and available here.
Except the packagingOptions
I could not find any differences that would be responsible for my awry. I tried to remove packagingOptions
but that did not make a single change at all.
[UPDATE 1]
You will notice that the more detailed error message states that it's in line #17 which is where I declare my native build settings.
I fixed the error which was cFlags
must be changed to CFlags
and I added the =
as required by the new version of Gradle.
This did help, the error does not appear anymore but changed for :
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
For the first part.
BuildType, flavors... are outside the android block, but inside the model block.