Gradle sync issue with Android Studio 0.5.1 - android-studio

Since updating to AS 0.5.1, I have been unable to sync up my project. Gradle gives me the following warning:
No signature of method: static com.google.common.collect.ArrayListMultimap.create() is applicable for argument types: () values: []
Possible solutions: clear(), grep(), get(java.lang.Object), get(java.lang.Object), getAt(java.lang.String), isCase(java.lang.Object)
It does not point to anything in my build.gradle file that may be causing the issue, so I am rather lost as to where to begin.
Edit: When attempting to run gradle build, I subsequently get this issue when applying the Android plugin:
A problem occurred evaluating root project 'tve-android'.
> Could not create plugin of type 'AppPlugin'.
My build.gradle file:
buildscript {
repositories {
mavenLocal()
maven {
url "http://nexus.products/nexus/content/groups/public"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
apply plugin: 'checkstyle'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
apply plugin: 'pmd'
android {
compileSdkVersion 19
buildToolsVersion "19.0.2"
defaultConfig.minSdkVersion = 16
defaultConfig.targetSdkVersion = 19
defaultConfig.testInstrumentationRunner = 'android.test.InstrumentationTestRunner'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/resources']
main.res.srcDirs = ['src/res']
main.assets.srcDirs = ['src/assets']
androidTest.java.srcDirs = ['src/test/java']
androidTest.resources.srcDirs = ['src/test/resources']
androidTest.res.srcDirs = ['src/res']
androidTest.assets.srcDirs = ['src/assets']
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.+'
compile 'commons-io:commons-io:2.+'
compile 'commons-lang:commons-lang:2.+'
compile 'com.loopj.android:android-async-http:1.4.+'
compile 'com.jakewharton:disklrucache:1.0.0'
compile 'net.jpountz.lz4:lz4:1.1.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.1'
androidTestCompile 'com.google.dexmaker:dexmaker:1.+'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.+'
androidTestCompile 'org.mockito:mockito-core:1.9.+'
}

Upgrading gradle to v1.10 is also needed.

I had the same issue and I quickly fix it just by re-import my gradle project.

Related

How do I import ok.io into android studio locally?

I have been trying to use ok.io, (version 1.14.1), locally in my project and it's been quite a struggle getting through the gradle requirements. My project requires that I include the source locally. I have managed to import the module but when attempting to run a build I end up with this error
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve project :okio.
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve project :okio.
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve project :okio.
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve project :okio.
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve project :okio.
I had thought this solution would be the way to go as it says all modules need to have the same build types and flavours. But this has not made a difference.
My (app) build.gradle looks like this
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.some.app.id"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {}
}
productFlavors {
}
compileOptions {
targetCompatibility 1.7
sourceCompatibility 1.7
}
}
dependencies {
.....
implementation project(path: ':okio')
}
The ok.io build.gradle looks like this
import com.github.jengelman.gradle.plugins.shadow.transformers.DontIncludeResourceTransformer
import com.github.jengelman.gradle.plugins.shadow.transformers.IncludeResourceTransformer
apply plugin: 'java-library'
apply plugin: 'org.jetbrains.kotlin.platform.jvm'
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'me.champeau.gradle.japicmp'
apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'me.champeau.gradle.jmh'
apply from: "$rootDir/gradle/gradle-mvn-push.gradle"
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
jar {
manifest {
attributes('Automatic-Module-Name': 'okio')
}
}
animalsniffer {
sourceSets = [sourceSets.main]
}
configurations {
baseline
}
jmhJar {
def excludeAllBenchmarkLists = new DontIncludeResourceTransformer()
excludeAllBenchmarkLists.resource = "META-INF/BenchmarkList"
transform(excludeAllBenchmarkLists)
def includeCorrectBenchmarkList = new IncludeResourceTransformer()
includeCorrectBenchmarkList.resource = "META-INF/BenchmarkList"
includeCorrectBenchmarkList.file = new File("$rootDir/okio/jvm/build/classes/java/jmh/META-INF/BenchmarkList")
transform(includeCorrectBenchmarkList)
}
jmh {
// The JMH plugin currently requires the Shadow plugin also be installed.
// See: https://github.com/melix/jmh-gradle-plugin/issues/97#issuecomment-374866151
include = ['com\\.squareup\\.okio\\.benchmarks\\.SelectBenchmark.*']
duplicateClassesStrategy = 'warn'
}
dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1#signature'
expectedBy project(':okio')
implementation deps.kotlin.stdLib.jdk6
compileOnly deps.animalSniffer.annotations
compileOnly deps.jsr305
testImplementation deps.test.junit
testImplementation deps.test.assertj
testImplementation deps.kotlin.test.jdk
baseline('com.squareup.okio:okio:1.14.1') {
transitive = false
force = true
}
jmh deps.jmh.core
jmh deps.jmh.generator
}
task japicmp(type: me.champeau.gradle.japicmp.JapicmpTask, dependsOn: 'jar') {
oldClasspath = configurations.baseline
newClasspath = files(jar.archivePath)
onlyBinaryIncompatibleModified = true
failOnModification = true
txtOutputFile = file("$buildDir/reports/japi.txt")
ignoreMissingClasses = true
includeSynthetic = true
classExcludes = [
'okio.SegmentedByteString', // internal
'okio.Util', // internal
]
methodExcludes = [
'okio.ByteString#getByte(int)', // became 'final' in 1.15.0
'okio.ByteString#size()', // became 'final' in 1.15.0
]
}
check.dependsOn(japicmp)
assemble.dependsOn(tasks['jmhJar'])
The module's structure in my project looks like this
Any advice on how to integrate ok.io locally and/or just "happy" module integration is greatly appreciated.

Android Gradle Failed to resolve

I am getting this error in the gradle file:
Error: Failed to resolve: com.google.android.gms:play-services-measurement:10.2.4
-Install Repository and sync project
-Open File
-Show in Project Structure dialog
But I don't use the play-services-measurement in my app.
In the other hand, if I click on the link "Install Repository and sync project" nothing happens.
Any could help me with this? I have been wasting days with this issue.
This is my full gradle file:
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileOptions {
encoding "UTF-8"
}
lintOptions {
disable 'MissingTranslation'
abortOnError false
}
defaultConfig {
applicationId "xxx.yyy.zzz"
minSdkVersion 9
targetSdkVersion 25
versionCode 120
versionName "1.20"
multiDexEnabled true
//Enabling multi dex support due to exceeding the 65K methods dex limit imposed by Android: http://stackoverflow.com/questions/29756188/java-finished-with-non-zero-exit-value-2-android-gradle
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "MyAppName")
newName = newName.replace("-release", "-release" + formattedDate)
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':simple-crop-image-lib')
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:10.2.4'
compile 'com.google.android.gms:play-services:10.2.4' //8.3.0' 10.2.4' 9.0.0' 9.6.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
//For soap:
compile files('libs/ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar')
}
apply plugin: 'com.google.gms.google-services'
Update Google Repository in Android SDK. Works for me with version 47.
From the firebase doc:
dependencies {
// ...
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-messaging:10.2.4'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
For me worked to remove these lines from the "app build.gradle":
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
And add these to the "project build.gradle":
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

jitpack.io dependencies are not working

I cannot get jitpack.io dependencies to work with gradle. I know there are other questions but none of the suggested tips helped. The problem is, jitpack.io dependencies are not working at all. In theory it should be simple... add the mavel { url ... } and the compile declarative. But i keep getting an error that the dependency cannot be resolved.
I updated android-studio, which suggested to update and then updated gradle. Since every jitpack.io dependency is not working, it must be related to the configuration of gradle overall. Unfortunately i have no clou where to start.
I tried different repositories, so that should not be the problem. I also checked the corresponding build logs.
Can anybody help me?
This are my whole gradle files, they should be fine.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "http://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "patrickstummer.com.bonario_internal"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.0.0-alpha2'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.github.soroushjavdan:ApplicationLocker:62301ce0b4'
}
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}

Import swagger-codegen project into existing Android project

Im trying to integrate a "module"-project generated by swagger-codegen, into my Android project.
Haven't worked that much with gradle before and the swagger-codegen creates a quite messy build.gradle from my point of view.
I have a hard time finding documentation on how to do this. And I feel a bit lost.
I used this method described in the FAQ
mvn clean package
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l java --library=okhttp-gson \
-o /var/tmp/java/okhttp-gson/
So fare I tried to copy the source from the project that was generated by swagger-codegen and merge the two gradle build files. I removed the Junit tests because I couldn't get the Junit dependency working (Implementing Swagger-codegen project - Error:(23, 17) Failed to resolve: junit:junit:4.12). But then I got stuck with some conflict between the plugins?
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Here's the build.gradle:
import static jdk.nashorn.internal.runtime.regexp.joni.ApplyCaseFold.apply
apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'io.swagger'
version = '1.0.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// classpath 'com.android.tools.build:gradle:1.5.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "\u0024{project.name}- \u0024{variant.baseName}-\u0024{version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
dependencies {
provided 'javax.annotation:jsr250-api:1.0'
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'XxxxXxxx'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
dependencies {
compile 'io.swagger:swagger-annotations:1.5.8'
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
compile 'com.google.code.gson:gson:2.6.2'
compile 'joda-time:joda-time:2.9.3'
// testCompile 'junit:junit:4.12'
}
Am I doing something complete wrong here? What is the correct way to implement swagger-codegen code into my project?
The swift way to import it was to compile the swagger generated project then copy the .jar file to my android project and add its as a library.
I have a hard time finding documentation on how to do this. And I feel a bit lost.
You could clone the Android swagger-codegen example.
(which does use Junit, so I'm not sure what error you got)
Unless that's what you mean by
So far I tried to copy the source and merge the two gradle build files
To which, I ask, what two Gradle files? It looks like you merged an Android Gradle file with a Java Gradle file, which seems to causing more issues because you are getting...
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Which seems pretty self explanatory when you have this line
apply plugin: 'java'
It's not too clear what you are trying to do here other than check the build target
if(hasProperty('target') && target == 'android')

Android Studio removes modules falsely identified as not backed by Gradle

I have a problem with Android Studio 0.3.0 and my project folder containing a plain old java library project, two Android library projects, and three Android apps. It's all built with Gradle.
The problem is that the initial import into Android Studio works fine (using Android Studio's Import Project..., then choosing my settings.gradle file), but when I press the refresh button in the Gradle sidebar, I get the message "The modules below are not backed by Gradle anymore. Check those to be removed from the ide project too:", and then it lists ALL my modules for removal. Everything builds fine from the terminal.
Output of gradle projects is (with edited names):
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'root'
+--- Project ':android-lib1'
+--- Project ':android-app1'
+--- Project ':android-app2'
+--- Project ':android-app3'
+--- Project ':android-lib2'
\--- Project ':java-lib'
In the root folder, I have settings.gradle:
include ':java-lib'
include ':android-lib1'
include ':android-lib2'
include ':android-app1'
include ':android-app2'
include ':android-app3'
My build.gradle in the root folder:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
allprojects {
repositories {
mavenCentral()
ivy {
name 'repo'
artifactPattern 'http://repo.example.com:8081/artifactory/libs-release-local/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]'
credentials {
username 'example'
password 'example'
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
build.gradle for java-lib:
apply plugin: 'java'
apply plugin: 'eclipse'
compileJava.options.encoding = 'UTF-8'
group 'example'
version '0.1.0'
status 'release'
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
dependencies {
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.google.guava:guava:15.0'
compile 'org.slf4j:slf4j-api:1.7.5'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
uploadArchives {
repositories {
add project.repositories.repo
}
}
build.gradle for the two Android libs (they are the same apart from dependencies and version numbers:
apply plugin: 'android-library'
dependencies {
compile project(':java-lib')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
versionCode 1
versionName '0.1.0'
minSdkVersion 9
targetSdkVersion 18
}
}
And finally, build.gradle for the Android apps (again, almost identical):
apply plugin: 'android'
dependencies {
compile project(':android-lib1')
compile project(':android-lib2')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
versionCode 1
versionName '0.1.0'
}
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
if (project.hasProperty('storeFile')) {
android.signingConfigs.release.storeFile = file(storeFile)
}
if (project.hasProperty('storePassword')) {
android.signingConfigs.release.storePassword = storePassword
}
if (project.hasProperty('keyAlias')) {
android.signingConfigs.release.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
android.signingConfigs.release.keyPassword = keyPassword
}
Perhaps it's a bug in Android Studio 0.3.0? I didn't experience it in earlier versions, but I want to make sure it's not just something in my build files.
Thanks a bunch for reading!
This was a bug which has now been fixed (working for me since Android Studio 0.3.5): https://code.google.com/p/android/issues/detail?id=61453
Also got this or very similar error (don't know if I did refresh) I see you posted bug at code.google.com and agree it must be their bug. My work around fix was just to cancel out of "not backed by Gradle" message and then I ran gradle build from command line. Then everything worked.

Resources