Android NDK sourceSets.main coundn't find jni - android

Like above, my build.gradle file cannot sync because it could not find property "jni" on source sets "main". I'm using gradle-experimental:0.7.0.
I wan't to use Android.mk file in compilation, but i cannot set srcDirs = [].
My build.gradle:
model {
android {
def globalConfiguration = rootProject.extensions.getByName("ext")
compileSdkVersion = globalConfiguration.getAt("androidCompileSdkVersion")
buildToolsVersion = globalConfiguration.getAt("androidBuildToolsVersion")
defaultConfig {
applicationId "com.example.ndk"
minSdkVersion.apiLevel globalConfiguration.getAt("androidMinSdkVersion")
targetSdkVersion.apiLevel globalConfiguration.getAt("androidTargetSdkVersion")
versionCode globalConfiguration.getAt("androidVersionCode")
versionName globalConfiguration.getAt("androidVersionName")
}
buildTypes {
release {
minifyEnabled false
proguardFiles.add(file('proguard-android.txt'))
// signingConfig signingConfigs.release
}
}
sourceSets {
def commonTestDir = 'src/commonTest/java'
test {
java.srcDir commonTestDir
}
androidTest {
java.srcDir commonTestDir
}
main {
jni.srcDirs = []
}
}
}
android.ndk {
moduleName = 'mymodule'
}
}

Take a look into the plugin Experimental Plugin User Guide, according to it, to specify the source directory, you have to do it like so:
model {
android {
...
sources {
main {
jni {
source {
srcDir "src"
}
}
}
}
}
}
It's not the way you did it. Take a look, here is the sources property used, but not the sourceSets

Related

ARToolkit gradle build error

I'm trying to use ntfSimpleProj example from ARToolkit.
I set the environment variables:
export ANDROID_HOME=/media/applica/Storage/Android/Sdk;
export ANDROID_NDK_ROOT=$ANDROID_HOME/ndk-bundle;
export NDK=$ANDROID_NDK_ROOT;
after I build successfully the two scripts in android folder ./build.sh and ./build_native_examples.sh
but the build of gradle return me this error:
Error:Attempt to read property 'main' from a write only view of model element 'android.sources' given to rule android.sources { ... } # nftSimple/build.gradle line 40, column 5
this is my gradle file:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.3"
defaultConfig.with {
applicationId = "org.artoolkit.ar.samples.NftSimple"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 1 //Integer type incremented by 1 for every release, major or minor, to Google store
versionName = "1.0" //Real fully qualified major and minor release description
buildConfigFields.with { //Defines fields in the generated Java BuildConfig class, in this case, for
create() { //default config, that can be accessed by Java code
type = "int" //e.g. "if (1 == BuildConfig.VALUE) { /*do something*/}".
name = "VALUE" //See: [app or lib]/build/generated/source/buildConfig/[package path]/
value = "1" // BuildConfig.java
}
}
ndk.with {
moduleName = "NftSimple"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
android.productFlavors {
}
android.sources {
main.jni {
source {
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.3"
defaultConfig.with {
applicationId = "org.artoolkit.ar.samples.NftSimple"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 1 //Integer type incremented by 1 for every release, major or minor, to Google store
versionName = "1.0" //Real fully qualified major and minor release description
buildConfigFields.with { //Defines fields in the generated Java BuildConfig class, in this case, for
create() { //default config, that can be accessed by Java code
type = "int" //e.g. "if (1 == BuildConfig.VALUE) { /*do something*/}".
name = "VALUE" //See: [app or lib]/build/generated/source/buildConfig/[package path]/
value = "1" // BuildConfig.java
}
}
ndk.with {
moduleName = "NftSimple"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
android.productFlavors {
}
android.sources {
srcDirs = ['src/main/nop']
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
}
dependencies {
//compile 'com.android.support:support-v4:23.0.1'
//compile 'com.android.support:appcompat-v7:23.0.1' //Only required when the target device API level is greater than
compile project(':aRBaseLib')
} //the compile and target of the app being deployed to the device
Can someone help me?
Thanks a lot!
I fixed the error, I have to change the sources declaration in the gradle.
From this:
android.sources {
srcDirs = ['src/main/nop']
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
To this:
android.sources {
main{
jni {
source {
srcDirs "src/main/nop"
}
}
jniLibs {
source {
srcDirs "src/main/libs"
}
}
}
}

Attempt to read property 'main' from a write only view of model element 'android.sources' given to rule android.sources { ... }

So I would like to use an Augmented Reality SDK (ARToolkit)
Unfortunately, the given code examples are a little outdated (using gradle 0.8 and stuff) so I had to modify the gradle file a little.
I got the following error now:
Error:Attempt to read property 'main' from a write only view of model element 'android.sources' given to rule android.sources { ... } # aRMarkerDistance\build.gradle line 23, column 5
Line 23 is the android.sources line.
Gradle file:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "org.ar.artoolkit.org.ARMarkerdistance"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 104
versionName = "1.0.4"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.pro'))
}
}
android.sources {
main.jni {
source {
srcDirs = ['src/main/nop']
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
}
dependencies {
compile project(':aRBaseLib')
}
Please help if you can.
Cause
In the gradle experimental the syntax has changed from main.jni to main{ jni {}}.
For more information on the most updated here is the link: http://tools.android.com/tech-docs/new-build-system/gradle-experimental
Solution
In order to solve this issue please replace your following gradle android.source with the following:
android.sources {
main {
jni {
source {
srcDirs = ['src/main/nop']
}
}
}
main {
jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
}

Converting native Android app to gradle-experimental 0.2.0

I'm trying to convert any project tango sample app to use the new experimental gradle build system. I downloaded an app, verified that it builds and deploys, and then updated files following the experimental-gradle guide. The process was straight-forward, except for the app build.gradle file, shown below before and after my edits. I have been studying the gradle plugin, the experimental guide, etc, but haven't figured out what to do with sourceSets and the two tasks and keep getting errors. What is the right way to modify build.gradle?
Note:
I used point-cloud-jni-example, but these changes should be the same for any project tango app, because the relevant files are essentially identical for all the tango sample apps.
stock app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.projecttango.experiments.nativepointcloud"
minSdkVersion 19
targetSdkVersion 19
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [];
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
modified app build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 19
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.projecttango.experiments.nativepointcloud"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 19
}
android.sourceSets.main {
jniLibs.srcDir = 'src/main/libs'
jni.srcDirs = [];
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
ndk.with {
debuggable = true
}
}
}
android.ndk {
moduleName = "point_cloud_jni_example"
ldLibs += ["android", "EGL", "GLESv2", "dl", "log"]
stl = "stlport_static"
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build.cmd"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I am not sure if it resolves all issues.
In any case, you have to change your buildTypes block using:
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
Also use the last version 0.2.1

Android Studio 1.3 gradle plugin returns error when defining jni and jniLibs in Source sets

Could not find property jni and source set 'main'
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.example.native_activity"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 9
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir = 'src/main/libs'
// This is not necessary unless you have precompiled libraries in your project.
}
}
Here is the stacktrace:
Caused by: org.gradle.model.internal.core.ModelRuleExecutionException: Exception thrown while executing model rule: model.android
at org.gradle.model.internal.registry.DefaultModelRegistry.fireMutation(DefaultModelRegistry.java:485)
at org.gradle.model.internal.registry.DefaultModelRegistry.access$1500(DefaultModelRegistry.java:45)
at org.gradle.model.internal.registry.DefaultModelRegistry$RunModelAction.apply(DefaultModelRegistry.java:1464)
at org.gradle.model.internal.registry.DefaultModelRegistry.transitionTo(DefaultModelRegistry.java:341)
at org.gradle.model.internal.registry.DefaultModelRegistry.transition(DefaultModelRegistry.java:419)
at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrMaybeLater(DefaultModelRegistry.java:183)
at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrLater(DefaultModelRegistry.java:175)
at org.gradle.execution.TaskNameResolver.selfClose(TaskNameResolver.java:101)
at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:114)
... 60 more
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method main() for arguments [build_f1cmjkxjjzysskbrs6852ixyj$_run_closure1_closure2_closure7#8c09fa7] on SourceSet container.
I googled like mad for the last 2 hours...
As Awanish said - read the Experimental Plugin User Guide step by step VERY carefully. For even more clearance check the build.gradle files in the ndk-samples provided by google.
sourceSets.main { } has different syntax and should be outside the android { } block. In your case it should look something like this:
model {
android {
//...
}
android.sources {
main {
jniLibs {
source {
srcDirs 'libs'
}
}
}
}
}
In my case it was an exact opposite to tochkov answer:
This syntax - with the jniLibs outside android block - gave me an error:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.myproject"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
and this syntax - inside android block - fixed it:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.myproject"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
It seems like you are trying to use the grade experimental plugin!
Make sure you have grade-2.5 in your gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
and this in your project's build.gradle dependencies tag
classpath 'com.android.tools.build:gradle-experimental:0.1.0'
Instead of guessing a lot of things, let me redirect you to the user guide, where the documentation explains migration from the standard to experimental plugin in detail. Take a look here!
Try these fixes. Post more details if these don't work for you, I will try to help. :)
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jeremy.test"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles.add(file('proguard-android.txt'))
}
}
ndk {
moduleName "hello-android-jni"
}
}
android.sources.main {
java.source.srcDirs = ["src/main/java", "/Users/jeremy/Repositories/hello/src/android/java"]
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
The above is copied from my experimental ndk project, this works for me.
See the android.sources.main section.

Android Studio add jar library error

I have follow the instruction to add jar library but when i am going to synchronize the build grade then getting error.
Could not find property 'file' on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#1a9bd9bb.
I am not getting what is error. please suggest.
build gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.cws.myapplication"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"));
}
}
}
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/layout'] } }
}
def var = dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile file 'libs/library-2.1.1.jar'
}
In Build.Gradle file the code to add the library is
compile files('libs/acra-4.6.0RC1.jar')
The letter 's' in 'files' is missing from the command.

Categories

Resources