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
Related
I am working on an android app with GluonMobile. For one feature I need a ExoPlayer.
So I included the dependency com.google.android.exoplayer:exoplayer:+ .
It seems that the dependecy is an aar -file and InteliJ could not find any of ExoPlayers classes.
Here my buildscript:
buildscript {
repositories {
mavenCentral()
jcenter()
google()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:+'
classpath 'com.github.jengelman.gradle.plugins:shadow:+'
}
}
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
repositories {
mavenCentral()
jcenter()
google()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
maven {
url uri('libs')
}
}
mainClassName = '[...].main.Main'
version = '2.0_Alpha'
dependencies {
compile "com.gluonhq:charm:+"
compile "com.gluonhq:glisten-afterburner:+"
compile "com.google.apis:google-api-services-youtube:+"
compile "com.google.api-client:google-api-client-java6:+"
compile "com.google.oauth-client:google-oauth-client-jetty:+"
compile "com.google.code.gson:gson:+"
compileOnly 'lib.idea:annotations:0'
androidImplementation "org.javafxports:jfxdvk:+"
androidImplementation 'com.google.android.exoplayer:exoplayer:+#aar'
}
jfxmobile {
downConfig {
version = '+'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
//noinspection GroovyAssignabilityCheck
plugins 'browser', 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
//androidSdk = "${ANDROID_HOME}"
compileSdkVersion = 28
targetSdkVersion = 22
minSdkVersion = 16
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
}
task installApk{
group = "gluon mobile for android"
doLast{
exec {
workingDir "${ANDROID_HOME}\\platform-tools"
commandLine "${workingDir}\\adb.exe", "install", "${buildDir}/javafxports/android/YouJavaTubeApp.apk"
}
}
}
I found already something about explodeAarDependencies(...) but it did not work. So have somebody any ideas how to include (any) aar dependencies to my GluonMobile project.
Thank you for your help.
You are on the right track about explodeAarDependencies, this is the task used by the jfxmobile plugin to unpack .aar dependencies into .jar and other resources.
You can find about the task here.
How to use it:
In your build.gradle file, include the dependency:
dependencies {
...
androidCompile 'com.google.android.exoplayer:exoplayer:2.9.0'
}
Note 1: don't to use #aar
Note 2: the jfxmobile plugin uses some defined configurations like androidCompile instead of androidImplementation.
Note 3: I'd rather use the given version, not +.
And at the end of the file, add the task:
project.afterEvaluate {
explodeAarDependencies(project.configurations.androidCompile)
}
And that's it.
Save and apply/sync/reload the build and you should see exoplayer and a bunch of transitive dependencies included into the Android compile dependencies, both .aar and .jar files.
I think you are adding dependencies in the wrong gradle file.
There will be 2 gradle files , One for project level and for app level. you need to add your libraries dependencies in app level gradle.
whereas you might be adding in the project level gradle.
My Gradle file looks like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.3"
defaultConfig {
applicationId "my.application.id"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.google.android.exoplayer:exoplayer:2.9.0'
}
For more details on adding exoplayer pls refer to
Github and
https://developer.android.com/guide/topics/media/exoplayer
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?
I'm trying to import a Jgrapht library in my app, but every time i try to build APK, android studio shows me:
Error:Execution failed for task ':app:transformClassesWithPreJackPackagedLibrariesForDebug'.
com.android.sched.scheduler.RunnerProcessException: Error during 'TypeLegalizer' runner on 'private final synthetic int org.jgrapht.alg.vertexcover.-$Lambda$25.$m$0(java.lang.Object arg0)': Unexpected error during visit: com.android.jack.ir.ast.JReturnStatement at "Unknown source info"
What is the problem and how i can fix it? Please help me!
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
defaultConfig {
applicationId "it.univpm.gruppoids.iotforemergencyandnavigation"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
compileOptions {
incremental true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
repositories {
maven {
url "https://mint.splunk.com/gradle/"
}
}
packagingOptions {
exclude 'META-INF/services/org.apache.sis.storage.DataStoreProvider'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
/*buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}*/
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:percent:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'com.google.zxing:core:3.2.1'
compile files('lib/jgrapht-ext-1.0.0-uber.jar')
compile files('lib/jgrapht-ext-1.0.0.jar')
compile files('lib/jgrapht-demo-1.0.0.jar')
compile files('lib/jgraph-5.13.0.0.jar')
compile files('lib/antlr4-runtime-4.5.3.jar')
compile files('lib/jgrapht-core-1.0.0.jar')
}
And the other gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
/*maven {
url "https://plugins.gradle.org/m2/"
}*/
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'me.tatarka:gradle-retrolambda:3.3.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
apply plugin: 'me.tatarka.retrolambda'
task clean(type: Delete) {
delete rootProject.buildDir
}
The easiest way I can think of is to use maven, then simply add the dependencies to your project. That'll save you a lot of hassel in setting up JGraphT by yourself.
you can find how to use maven with android studio here: How to import Maven dependency in Android Studio/IntelliJ?
While JGraphT's dependencies are here under the "Maven Releases" section:
http://jgrapht.org/
:app:mergeDebugAssets
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK kotlin/internal/internal.kotlin_builtins
File1: /Users/KD/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.0.4/172b43fbc03b521fed141484b212d6725fa671a9/kotlin-compiler-embeddable-1.0.4.jar
File2: /Users/KD/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-runtime/1.0.4/8e25da5e31669f5acf514bdd99b94ff5c7003b3b/kotlin-runtime-1.0.4.jar
My build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.app2par.ctime"
minSdkVersion 16
// minSdkVersion 21
// targetSdkVersion 23
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled false
// multiDexEnabled true
}
dexOptions {
preDexLibraries true
javaMaxHeapSize "2g" // Use gig increments depending on needs
incremental true
}
buildTypes {
debug {
minifyEnabled false
// testCoverageEnabled true
// ext.betaDistributionReleaseNotes = getCrashlyticsBetaMessage()
// ext.betaDistributionGroupAliases = 'team'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
// dataBinding {
// enabled = true
// https://code.google.com/p/android/issues/detail?id=187443&q=attachments%3D0&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
// }
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':firebasesync')
compile project(':liboid')
compile project(':cloudtimemodel')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support'
}
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
// transitive = true;
// }
// compile 'com.google.android.gms:play-services:5.0.89'
// compile 'com.google.android.gms:play-services:7.0.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// compile 'com.firebase:firebase-client-android:2.0.3.+'
// compile 'com.google.android.gms:play-services-safetynet:8.3.0'
// compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-plus:7.0.0' // play-services-plus:7.0.0 : office-mover
// compile 'com.google.android.gms:play-services-auth:8.3.0' // play-services-auth:8.3.0 : ShoppingList++
// compile 'com.google.android.gms:play-services-identity:7.0.0'
}
buildscript {
// ext.kotlin_version = '1.0.0-rc-1036'
ext.kotlin_version = '1.0.4'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath 'org.ajoberstar:grgit:1.1.0'
// classpath 'io.fabric.tools:gradle:1.+'
// classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.5.0-x'
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
How to fix or diagnose this?
You should remove compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" from your dependencies section and move it to buildscript { dependencies { ... } }.
You did put compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" in the wrong build.gradle file
You may use kotlin plugin's build-in converters to deal with this. According to Kotlin Docs:
Configuring Kotlin in the project
When adding a new Kotlin file, IntelliJ IDEA (and Android Studio)
automatically prompts us as to whether we'd like to configure the
Kotlin runtime for the project. However, currently, converting
existing Java file does not prompt this action. Therefore we have to
invoke it manually (via Find Action):
We are then prompted for the version of Kotlin. Choose the latest
available from the list of installed versions.
After we configure Kotlin, build.gradle file for the application
should be updated. Now we can see that apply plugin: 'kotlin-android'
and the dependencies were added.
(For more details how to set up gradle for your project, please check
Using Gradle)
The last thing to do is to sync the project. We can press Sync Now
in a prompt or invoke an action Sync Project with Gradle Files.
From: https://kotlinlang.org/docs/tutorials/kotlin-android.html
Check link above for more information.
Hope it will help.
you need to apply only one plugin, in your case apply plugin: 'kotlin-android-extensions' and only compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" this dependency. it worked for me
com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description
occurring while trying to do a debug build/test either via Android Studio or via Gradle command-line on my application.
The release build (without tests) works fine but as soon as testing is included (hamcrest being a testing library), the build fails with the above error.
I've checked my module dependencies and there's no duplicate requirements which gradle -q dependencies corroborates.
Project settings.gradle
include ':[library module]'
include ':[main module]'
Project build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
[library module] build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.google.zxing:core:3.0.+'
compile 'com.bugsnag:bugsnag-android:2.1.1+'
}
[main module] build.gradle
apply plugin: 'android'
android {
signingConfigs {
release {
[...]
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['src/main/res']
}
androidTest {
setRoot('src/test')
}
instrumentTest {
}
}
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
testPackageName "[main.packageName].tests"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
apply plugin: 'android-test'
androidTest {
// configure the set of classes for JUnit tests
include '**/*Test.class'
// configure max heap size of the test JVM
maxHeapSize = "2048m"
}
repositories {
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
androidTestCompile 'junit:junit:4.10'
androidTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
androidTestCompile 'com.squareup:fest-android:1.0.+'
compile project(':[library module]')
compile 'com.github.gabrielemariotti.changeloglib:library:1.4.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:+'
compile ('de.keyboardsurfer.android.widget:crouton:1.8.+') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile files('libs/CWAC-LoaderEx.jar')
compile 'com.squareup.okhttp:okhttp:1.5.+'
compile 'com.octo.android.robospice:robospice:1.4.11'
compile 'com.octo.android.robospice:robospice-cache:1.4.11'
compile 'com.octo.android.robospice:robospice-retrofit:1.4.11'
compile 'com.commonsware.cwac:security:0.1.+'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
}
I solved the error by looking in Android Studio for the exact class called 'Description'. It turned out to be present in 3 jars. One from junit, one from a direct dependency and one from mockito.
It turns out that junit, instead of a normal dependency, includes the Hamcrest classes in the junit jar.
To be able to solve the problem include junit-dep instead of junit.
so change
androidTestCompile('junit:junit:4.8.+')
to
androidTestCompile('junit:junit-dep:4.8.+')
Mockito has the same problem/solution: use mockito-core.1.9.5.jar instead of mockito-all.1.9.5.jar
My project had a dependency on json-simple version 1.1.1, which for some reason has a run-time dependency on junit version 4.1.0, which itself has a dependency on Hamcrest. I could see this if I ran gradle dependencies or alternatively by inspecting the json-simple POM.xml.
// compile - Classpath for compiling the main sources.
\--- com.googlecode.json-simple:json-simple:1.1.1
\--- junit:junit:4.10
\--- org.hamcrest:hamcrest-core:1.1
Excluding the junit artifact from json-simple allowed me to build.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.googlecode.json-simple:json-simple:1.1.1') {
exclude module: 'junit'
}
}
Robolectric 2.3 depends on JUnit 4.8.1 (version explicit). You're importing JUnit 4.10 (version explicit). Hamcrest is probably simply the first of many duplicates that dex is choking on - try changing your JUnit requirement version to 4.8+ (or excluding JUnit from the Robolectric dependency).
exclude module: junit
if you are using json:simple dependency