Android annotations gradle warning - android

I'm using Android Studio 1.1 beta 4 with gradle plugin 1.0.1 and trying to add Android Annotations to my project following the official insturctions. So I get the following build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "ru.itloft.moneytracker"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
}
def AAVersion = '3.2'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'
compile 'com.google.code.gson:gson:2.3'
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
// if you have multiple outputs (when using splits), you may want to have other index than 0
resourcePackageName 'ru.itloft.moneytracker'
// If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
// resourcePackageName android.defaultConfig.packageName
// You can set optional annotation processing options here, like these commented options:
// logLevel 'INFO'
// logFile '/var/log/aa.log'
}
}
And all works fine, but I get a warning in the line androidManifestFile variant.outputs[0].processResources.manifestFile saying: 'getAt' in 'org.codehaus.groovy.runtime.DefaultGroovyMethods' cannot be applied to '(java.lang.Integer)'. How can I get rid of this warning?

How #WonderCsabo already told this is a false positive. You can avoid this warning if you access the outputs explicit as collection
androidManifestFile variant.outputs.collect()[0].processResources.manifestFile

Related

Imported Android Module Doesn't Include Dependencies

I'm working on an Android library that allows communication with a Bluetooth device. The library itself has two important dependencies.
The goal is to make an .aar available of the library for others to include in their apps, with a sample app being available for reference.
I'm currently working on the sample app, and I've successfully imported the library into the app, but the library's dependencies are not being included so I'm receiving errors such as java.lang.NoClassDefFoundError: Failed resolution of: ...
It was my understanding that the library's gradle file would be used when compiling the library, but this does not seem to be the case?
My library's gradle file is as follows:
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
}
}
repositories {
mavenLocal()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
publishNonDefault true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:support-annotations:25.3.1'
compile 'com.polidea.rxandroidble:rxandroidble:1.3.2'
compile 'com.github.zafarkhaja:java-semver:0.9.0'
testCompile 'junit:junit:4.12'
}
Any ideas?

Inconsistent behavior when compiling Android apps

I have two Android apps I'm looking at - one that I created a while back and another that I'm just making now. When I try to compile the new one, I get an error "Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
compileSdkVersion 'android-25' requires JDK 1.8 or later to compile." I do not get this error with the old app. Why the difference?
New app's gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.jtriemstra.forceconnectfromphone"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.0'
}
Old app's gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.jtriemstra.timeswitch"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-codec:commons-codec:1.10'
compile 'com.android.support:appcompat-v7:25.0.0'
compile files('libs/nmdp_speech_kit.jar')
}
In both cases, if I go to File > Project Structure, I see it pointed to the same JDK 1.7 path.
The biggest difference I can see is that the new app is using a newer version of Gradle and the Gradle wrapper...which I changed in an effort to solve another problem (see Why "This app has been built with an incorrect configuration" error occured in some phones?) But I would have expected a compile failure to be more at the javac level, not the build manager level.
It looks like the reason is, in fact, the gradle wrapper. If I take a different approach to solving my initial problem, and roll back my changes to the wrapper to use v2.8, the project compiles.

How to use Android Annotations and its annotation processor with jack?

Does anybody know how to use Android Annotations with the jack compiler ?
Here my app/build.gradle and here my project build.gradle
With this configuration, I have this error message when I build my project :
Error:Could not get unknown property 'classpath' for task ':app:transformJackWithJackForDebug' of type com.android.build.gradle.internal.pipeline.TransformTask.
You should remove the android-apt plugin and the apt block completely, because it does not work with Jack annotation processing. Also, you have to declare processsors in the annotationProcessor configuration. Lastly, you have to add the annotation processing parameters to jack (which has no public API per-variant, yet).
Here is your modified build.gradle:
repositories {
jcenter()
mavenCentral()
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.frlgrd.streamzone"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
// Android Annotations
def AAVersion = '4.0.0'
dependencies {
// Google
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
// Android Annotations
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
// RX
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.7.1#aar'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
}
// add annotation processing options to jack
android.applicationVariants.all { variant ->
variant.variantData.variantConfiguration.javaCompileOptions.annotationProcessorOptions
.arguments = ['androidManifestFile': variant.outputs[0]?.processResources?.manifestFile?.absolutePath]
}

Android Gradle error occurs

Error:(1, 0) Plugin is too old, please update to a more recent version,
or set ANDROID_DAILY_OVERRIDE environment variable to
"f4a0bcdad02706f1af97b485d6a6a0c5e7d9a560". Fix plugin version and sync project
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.app.xxxxxx"
minSdkVersion 15
targetSdkVersion 21
versionCode 2
versionName "2.0"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.config
debuggable true
jniDebuggable false
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.+'
}
Update your Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.app.xxxxxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName "2.0"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.config
debuggable true
jniDebuggable false
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
}
Also Your Gradle version
//You Used Above Version Also
classpath 'com.android.tools.build:gradle:2.1.0'
its because your gradle plugin is too old, you need to update it to latest version.
Download the latest Gradle from here
You will need run sdk manager and check for updated revisions.
In Project level build.gradle:
Replace:
classpath 'com.android.tools.build:gradle:1.1.0'
with:
classpath 'com.android.tools.build:gradle:2.1.2'
and in the app level build.gradle which you have posted above:
Replace:
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.+'
With:
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'

Android Studio 0.8.1 Robolectric Setup

I am trying to get robolectric working for new Android 0.8.1 since currently there is no robolectric gradle 0.12 plugin so I am hoping that .11 will work for now.
* Problem:
androidTestCompile 'org.robolectric:robolectric:2.3'
Using the following declaration to compile robolectric, I am unable to find "org.robolectric.*" in my test directory, studio gives "cannot resolve symbol..." error.
According to the following projects you have to manually update the iml file. This is probably not the best solution since updating gradle file overwrites any changes you have made.
Would appreciate help on this matter!! thank you.
* Current project structure is:
src -> main -> java
src -> test -> java
* Below is my current build.gradle module file:
apply plugin: 'android-library'
apply plugin: 'robolectric'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
allprojects {
repositories {
jcenter()
}
}
android {
compileSdkVersion 16
buildToolsVersion '19.1.0'
publishNonDefault true
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId 'com.myapp.example.main'
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
sourceSets {
androidTest {
setRoot('src/test/java')
}
}
lintOptions {
abortOnError false
disable 'InvalidPackage'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:+'
compile files('libs/gson-2.2.4.jar')
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:support-v13:+'
/* Including testing libraries */
androidTestCompile 'junit:junit:4.10'
androidTestCompile 'org.robolectric:robolectric:2.3'
}
robolectric {
// configure the set of classes for JUnit tests
include '**/*Test.class'
// configure max heap size of the test JVM
maxHeapSize = "2048m"
}
It's a bit later for now. But I ran into this error as well and it turned out the version of Robolectric in my dependencies was outdated. After I replaced it with the newest one found here, I fixed the error. Also, you may change the androidTestCompile to testCompile since you're writing unit test here. You can find the difference between the two here

Categories

Resources