ARToolkit gradle build error - android

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

Related

Error:Cannot set readonly property: proguardFiles for class: com.android.build.gradle.managed.BuildType

I am trying to run an AR sample app from: https://artoolkit.org/documentation/doku.php?id=4_Android:android_examples
I tried to open the project ARSimpleProj. But it gives me this error:
Error:Cannot set readonly property: proguardFiles for class: com.android.build.gradle.managed.BuildType
I am using Android Studio 2.2.2 and Gradle 2.14.1
Thanks!
According to
this description , in version 0.4.0 , '+=' was desabled and instead use ".add()" for it .
So make the statement
proguardFiles += file('proguard-rules.pro')
change to
proguardFiles.add(file('proguard-rules.pro'))
and the error will disappear
The build.gradle file now looks like the following ...note the changes..there are 2-3 changes done
but now working absolutely fine.The code is below:-
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "org.artoolkit.ar.samples.ARSimple"
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
}
}
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.pro'))
}
}
android.productFlavors {
}
android.sources {
main{
jni {
source {
srcDirs = ['src/main/nop']
}
}
}
main{
jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
}
}
dependencies {
compile project(':aRBaseLib')
}
I got the same error last a few hours. I solved by changing build type as follow -
buildTypes {
release {
minifyEnabled false
proguardFiles 'proguard-rules.pro'
}
}
After that I deleted all ndk imported code line. So my build.gradle of aRSimple is -
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "org.artoolkit.ar.samples.ARSimple"
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
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles 'proguard-rules.pro'
}
}
android.productFlavors {
}
}
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
Then I create and copied all the .so library file into the jnilibs in applicaion main folder as show in fig
fig
Then run yours.
I don't know this is the solution for this. But the errors go and project run without errors. Tell me if you find any other solution for this. Thanks.
Getting the files from Github fixed it for me. I followed the short read me that they had in order to link the files to where you have saved the SDK and reopened from within that directory. I couldn't get the above answer to work for me. Perhaps something changed as I had all the .so libs; else I did it wrong.

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']
}
}
}
}

Android NDK sourceSets.main coundn't find jni

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

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.

how append date build to versionNameSuffix on gradle

I am using Android Studio and I need to append a suffix to the versionNameSuffix on my Android build.gradle file. I have three different build types and I only need to append the datetime to my "beta" release. My actual file is:
defaultConfig {
versionCode 14
versionName "0.7.5"
minSdkVersion 9
targetSdkVersion 18
}
buildTypes {
beta {
packageNameSuffix ".beta"
versionNameSuffix "-beta"
signingConfig signingConfigs.debug
}
....
}
For testing and automatic deploy, I need to get a final versionName like: 0.7.5-beta-build20131004, 0.7.5-beta-build1380855996 or something like that. Any ideas?
beta {
packageNameSuffix ".beta"
versionNameSuffix "-beta" + "-build" + getDate()
signingConfig signingConfigs.debug
}
def getDate() {
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmmss')
return formattedDate
}
Condensed:
def getDate() {
return new Date().format('yyyyMMddHHmmss')
}
You can define in your build.gradle custom functions and variables.
def versionMajor = 3
def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'") // you can change it
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
Then you can use it:
android {
defaultConfig {
versionName "${versionMajor}-beta-build-${buildTime()}"
}
}
or if you want to add it in you versionNameSuffix
beta {
versionNameSuffix "-beta-build-${buildTime()}"
}
Also, do not forget to add import as Gradle first line:
import java.text.SimpleDateFormat;
...
for simple one row solution define this property above android section
final BUILD_DATE = new Date().format('yyyy_MM_dd_HHmm')
and then
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId APPLICATION_ID
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.compileSdkVersion
versionName GIT_TAG_NAME
versionCode GIT_COMMIT_COUNT
setProperty("archivesBaseName",`enter code here` "com-appname-$BUILD_DATE-$versionName")
}
}
I'm not familiar with Android Studio, but I'll assume Gradle behaves as it normally does. Adding something like this to your build project configuration should do the trick:
allProjects {
gradle.taskGraph.whenReady { taskGraph ->
versionNameSuffix += '-build' + // Java/Groovy code to produce the timestamp formatted the way you want
}
}
This is for Kotlin DSL (build.gradle.kts):
// At the top of the file
import java.time.LocalDate
import java.time.format.DateTimeFormatter.*
// ...
android {
buildTypes {
getByName("debug") { // OR simply debug { in newer versions of Android Gradle Plugin (AGP)
val date = LocalDate.now().toString()
// OR val date = LocalDate.now().format(ISO_LOCAL_DATE)
// OR val date = LocalDate.now().format(ofPattern("yyyy-MM-dd"))
versionNameSuffix = date
}
}
}
You could also extract the date creation to a function:
android {
buildTypes {
getByName("debug") {
versionNameSuffix = generateDate()
}
}
}
fun generateDate() = LocalDate.now().toString()
// OR fun generateDate() = LocalDate.now().format(ISO_LOCAL_DATE)
// OR fun generateDate() = LocalDate.now().format(ofPattern("yyyy-MM-dd"))
You can test
task timenow {
println(new Date().getTime())
}
Run gradle: gradle timenow
See details. Place it on the top-level build
ext {
configuration = [
appName : "vBulletin",
applicationId : "com.vbulletin",
minSdkVersion : 14,
targetSdkVersion : 19,
compileSdkVersion: 19,
versionCode : 6,
versionName : "1.3.6",
buildToolsVersion: "25.0.0",
]
}
task createBrand {
appConfig.applicationId = appConfig.applicationId + ".${brand}"
appConfig.versionCode = new Date().getTime()
appConfig.versionName = version
}

Categories

Resources