I have just started using android studio 1.1.0 and cannot get over the problem of adding an external jar in my project.
I am building an extremely simple app that runs perfectly well as long as I don't try to add the external jar in my app module. The jar I am trying to add is named 'xstream-1.4.8.jar'. I pasted the jar file in the 'libs' folder in my app module. Then in the project explorer tab on left hand side, I right clicked on the 'xstream-1.4.8.jar' in the 'libs' section and chose the 'add as library..' option.
Now the dependencies section of build.gradle in the src folder of my app module reads as :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/xstream-1.4.8.jar')
}
When I build the project, it build perfectly fine without any error. But when I try to run the app, then I get the following error :
The event log reads as :
Gradle build finished with 1 error(s) in 15 sec
And the messages section reads as:
Information:Gradle tasks [:app:assembleDebug] :app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE :app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig
UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets
UP-TO-DATE :app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE :app:mergeDebugResources
UP-TO-DATE :app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE :app:generateDebugSources
UP-TO-DATE :app:compileDebugJava UP-TO-DATE :app:preDexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic
(cafebabe) or version (0034.0000) at
com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at
com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at
com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at
com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704) at
com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) at
com.android.dx.command.dexer.Main.access$300(Main.java:83) at
com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at
com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at
com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at
com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632) at
com.android.dx.command.dexer.Main.processAllFiles(Main.java:510) at
com.android.dx.command.dexer.Main.runMonoDex(Main.java:280) at
com.android.dx.command.dexer.Main.run(Main.java:246) at
com.android.dx.command.dexer.Main.main(Main.java:215) at
com.android.dx.command.Main.main(Main.java:106) ...while parsing
com/thoughtworks/xstream/mapper/LambdaMapper.class 1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with
non-zero exit value 1
Information:BUILD FAILED
I have already tried cleaning the project several times, but that doesn't help. Every time I try to run the app, I get this error. I have also built a normal java project using the same .jar file in eclipse which runs perfectly without any issues. What am I doing wrong?
You have to compile your java project (jar) with JDK 1.7.
if you use JDK 1.8, set the target to 1.7
By the way,you don't need to add this line in the dependencies block of your build.gradle.
compile files('libs/xstream-1.4.8.jar')
This line is enough.
compile fileTree(dir: 'libs', include: ['*.jar'])
You can use:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
Related
I'm trying to write a BitBucket Pipeline script for my repository, but so far without much luck, because Gradle seems a pain to debug.
Is there any way to show the resulting files (from compiling the jar for example) in the console when it finishes the : build task?
Preferably I'd like to see as much information as possible, rather too much than too little.
Adding logging.captureStandardOutput LogLevel.DEBUG in my build.gradle file didn't seem to do much, still getting the same output:
:compileJavaNote: -snip-\src\main\java\com\-snip-\atlas\utility\SchematicUtil.java uses or overrides a deprecated API.
Note: Recompile with -Xlint: deprecation for details.
:processResources
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.16 secs
Here's one way to do it (e.g. jar for a simple Java project). The build.gradle is:
apply plugin: 'java'
jar {
doLast {
new File("${buildDir}/libs").eachFileRecurse { file ->
println "TRACER: ${file.getAbsolutePath()}"
}
}
}
It should be straight-forward to tailor for other needs.
I'm trying to compile and deploy my Android App, but i have got an MultiDex issue :
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.lang.UnsupportedOperationException (no error message)
I already tryed many fix but they doesn't works.
What i already tryed :
1. multiDexEnabled true
2. dexOptions
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
3. Turning off Instant Run in Android Studio settings
4. Reboot Android Studio and computer.
5. Clear and Rebuild project.
6. File > Invalidate Caches / Restart.
7. compile 'com.android.support:multidex:1.0.1' [EDIT]
And finally reboot my life but nothing want to works..
What can be done to fix this problem ?
Here is my Gradle file
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion '24.0.1'
defaultConfig {
applicationId "com.X.Y"
minSdkVersion 15
targetSdkVersion 21
versionCode 90
versionName "1.2.3"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
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'
}
}
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://dl.bintray.com/X/maven/' }
maven { url "https://jitpack.io" }
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
// Utils
//ANR Helper & Memory Leaks helper
//compile 'com.github.anrwatchdog:anrwatchdog:1.1.+'
//compile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
// HoneyWell sdk
compile files('libs/honeywell.jar')
// RealmAdapter
compile 'io.realm:android-adapters:1.2.1'
// Volley
compile 'com.mcxiaoke.volley:library:1.0.19'
// EventBus
// compile 'org.greenrobot:eventbus:3.0.0'
// Gson
compile 'com.google.code.gson:gson:2.3.1'
// Jjp
compile 'com.instagram:ig-json-parser-processor:0.0.6+'
// Sticky List headers
compile 'se.emilsjolander:stickylistheaders:2.7.0'
// Parallax
compile 'com.github.nirhart:parallaxscroll:1.0'
// Facebook
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
// Zbar
compile 'me.dm7.barcodescanner:zbar:1.9'
// NumberProgressBar
compile 'com.daimajia.numberprogressbar:library:1.2#aar'
// AutoFitTextView
compile 'me.grantland:autofittextview:0.2.+'
// RoundedImageView
compile 'com.makeramen:roundedimageview:2.2.0'
// UpdateChecker
compile 'com.github.rampo.updatechecker:library:2.1.8'
// UniversalImageLoader
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
// GifDrawable
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
// PieChart
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'
compile 'com.android.support:support-v13:+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
//AndroidSlidingUpPanel
compile 'com.sothree.slidinguppanel:library:3.3.0'
// YPL
compile 'com.X:Xandroidlibrary:1.4.0'
compile project(':kdcreader')
}
And here Gradle Console
Executing tasks: [:app:assembleDebug]
Configuration on demand is an incubating feature. WARNING: WARNING:
Dependency org.apache.httpcomponents:httpclient:4.3.5 is ignored for
debug as it may be conflicting with the internal version provided by
Android.
In case of problem, please repackage it with jarjar to change the class packages WARNING: WARNING: Dependency
org.apache.httpcomponents:httpclient:4.3.5 is ignored for debug as it
may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages WARNING: WARNING: Dependency
org.apache.httpcomponents:httpclient:4.3.5 is ignored for release as
it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages WARNING: WARNING: Dependency
org.apache.httpcomponents:httpclient:4.3.5 is ignored for release as
it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages :app:preBuild UP-TO-DATE :app:preDebugBuild
UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCompat2510Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUi2510Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUtils2510Library UP-TO-DATE
:app:prepareComAndroidSupportSupportFragment2510Library UP-TO-DATE
:app:prepareComAndroidSupportSupportMediaCompat2510Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV132510Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42510Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidAnswers136Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidBeta114Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlytics255Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlyticsCore238Library
UP-TO-DATE :app:prepareComDaimajiaNumberprogressbarLibrary12Library
UP-TO-DATE :app:prepareComFacebookAndroidFacebookAndroidSdk460Library
UP-TO-DATE :app:prepareComGetkeepsafeRelinkerRelinker122Library
UP-TO-DATE :app:prepareComGithubNirhartParallaxscroll10Library
UP-TO-DATE :app:prepareComGithubRampoUpdatecheckerLibrary218Library
UP-TO-DATE :app:prepareComMakeramenRoundedimageview220Library
UP-TO-DATE :app:prepareComSothreeSlidinguppanelLibrary330Library
UP-TO-DATE :app:prepareComXXnandroidlibrary140Library
UP-TO-DATE :app:prepareIoFabricSdkAndroidFabric1310Library UP-TO-DATE
:app:prepareIoRealmAndroidAdapters121Library UP-TO-DATE
:app:prepareIoRealmRealmAndroidLibrary211Library UP-TO-DATE
:app:prepareMeDm7BarcodescannerCore19Library UP-TO-DATE
:app:prepareMeDm7BarcodescannerZbar19Library UP-TO-DATE
:app:prepareMeGrantlandAutofittextview021Library UP-TO-DATE
:app:preparePlDroidsonroidsGifAndroidGifDrawable1117Library UP-TO-DATE
:app:prepareSeEmilsjolanderStickylistheaders270Library UP-TO-DATE
:app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig
UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders
UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets
UP-TO-DATE :app:processDebugManifest UP-TO-DATE
:app:fabricGenerateResourcesDebug :app:generateDebugResValues
UP-TO-DATE :app:generateDebugResources :app:mergeDebugResources
:app:processDebugResources :app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk
UP-TO-DATE :app:compileDebugSources UP-TO-DATE
:app:transformClassesWithRealmTransformerForDebug UP-TO-DATE
:app:transformClassesWithJarMergingForDebug UP-TO-DATE
:app:transformClassesWithMultidexlistForDebug FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.lang.UnsupportedOperationException (no error message)
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.277 secs
[EDIT] And more info about crash : http://pastebin.com/vG79DLuN
Thanks for your help !
I had a same issue. In my app I am using guava-retrying library, which was fetching google guava library version 21. Guava version 21 requires JDK 1.8 without providing back porting support and this was causing this error in my case.
I was able to solve it by including the guava-retrying library so that it uses version 19.0 of guava library:
compile ("com.github.rholder:guava-retrying:2.0.0") {
exclude group: 'com.google.guava', module: 'guava'
}
compile 'com.google.guava:guava:19.0'
I am using Comriva library to extract MFCC features to my speech recognition project. And i have imported the comriva core packages to my project. When i tired to build it im getting this error in gradle,
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72220Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:collectDebugMultiDexComponents UP-TO-DATE
:app:packageAllDebugClassesForMultiDex UP-TO-DATE
:app:shrinkDebugMultiDexComponents UP-TO-DATE
:app:createDebugMainDexClassList UP-TO-DATE
:app:dexDebug
trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 5.524 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
I didn't include any xml libraries so far like simple-xml.
This is my gradle.build file,
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "info.androidhive.sleepApp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile files('libs/jl1.0.jar')
compile files('libs/commons-logging-api.jar')
compile files('libs/cp.jar')
compile files('libs/http-2.2.1.jar')
compile files('libs/jama-1.0.2.jar')
compile files('libs/jl1.0.jar')
compile files('libs/jogg-0.0.7.jar')
compile files('libs/lucene-analyzers-3.0.0.jar')
compile files('libs/lucene-core-3.0.0.jar')
compile files('libs/lucene-queries-3.0.0.jar')
compile files('libs/lucene-queryparser-3.0.0.jar')
compile files('libs/lucene-snowball-3.0.3.jar')
compile files('libs/jorbis-0.0.15.jar')
compile files('libs/mdsj.jar')
compile files('libs/tritonus_remaining.jar')
compile files('libs/tritonus_share.jar')
compile files('libs/wstx-lgpl-3.0.1.jar')
compile files('libs/weka-stable-3.6.13.jar')
compile files('libs/stax-api-1.0.jar')
compile files('libs/mp3spi1.9.4.jar')
}
Please help me to overcome this problem.
I figured out the issue it was the stax-api-1.0.jar this included the javax.xml.stream.events.* classes after removing the jar i was able to build it successfully. This jar came with the comriva that is why i didn't notice it.
I am trying to write an instrumentation test for my MainActivity. I followed the answers given here. Still Android Studio cannot find any tests. I have the class ApplicationTest.java in the androidTest folder. Here's the contents of the class:
package com.example.monicamarcus.mymusicplayer
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import com.example.monicamarcus.mymusicplayer.MainActivity;
public class ApplicationTest extends ActivityInstrumentationTestCase2<MainActivity> {
public ApplicationTest() {
super(MainActivity.class);
}
public void testNextTrackButton() throws Exception {
Activity activity = getActivity();
Button nextButton = (Button) activity.findViewById(R.id.nextTrackBt);
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
nextButton.performClick();
assertTrue(currentPosition < songList.size());
}});
activity.finish();
}
}
What is wrong with this test class? Or with the tests? I don't get any error, it just does not find any test to run. After I run the ApplicationTest the output ends with the following lines:
Running tests
Test running startedFinish
Empty test suite.
Here's the build.gradle file for the app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.monicamarcus.mymusicplayer"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testApplicationId "app.src.androidTest.java.com.example.monicamarcus.mymusicplayer"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
android {
sourceSets {
androidTest {
java.srcDirs = ['androidTest/java']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
androidTestCompile 'junit:junit:4.12'
}
Here's the output of the test run:
Testing started at 1:56 PM ...
Target device: gt_i8190n-4790068ee9a750c6
Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug.apk
Uploading file to: /data/local/tmp/com.example.monicamarcus.mymusicplayer
Installing com.example.monicamarcus.mymusicplayer
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.monicamarcus.mymusicplayer"
pkg: /data/local/tmp/com.example.monicamarcus.mymusicplayer
Success
Installing APK: /Users/monicamarcus/AndroidStudioProjects/MyMusicPlayer/app/build/outputs/apk/app-debug-androidTest-unaligned.apk
Uploading file to: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
Installing app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer"
pkg: /data/local/tmp/app.src.androidTest.java.com.example.monicamarcus.mymusicplayer
Success
Running tests
Test running startedFinish
Empty test suite.
After I made some changes (I can publish them if anybody is interested) the result of running the instrumentation test class read as follows: "Running tests. Test running started. Test running failed: No test results. Empty test suite." Nobody has experience with these kind of tests?
In build.gradle, testApplicationId looks very strange. I would remove this and testInstrumentationRunner. The default values should be fine. Specifically, if you do not specify testApplicationId, it will be created by appending ".test" to your applicationId.
not sure if the problem has been found. Running into similar but only if added assertTrue() it got the "Empty test suite.".
but replace with assertNotNull() the test is fine, still cannot use assertTrue though (not know why).
(I'm using kotlin and modify the Android studio generated default test in the AndroidTest folder, and the test is coded in kotlin's companion object, if this make any difference).
Update: using assertTrue() outside the companion object is fine.
i just created a new project in android studio 2.2.2, made an android test fail did a gradle cC, and got the output below.
you can see the test failing on each device at the bottom of the output.
this question may be related.
the reports are in So35426990/app/build/reports/androidTests/connected/index.html
d:\AndroidStudioProjects\So35426990>gradle cC
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be
removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpty() instea
d.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2421Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72421Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2421Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUi2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportCoreUtils2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportFragment2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportMediaCompat2421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42421Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2421Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:transformClassesWithDexForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:validateSigningDebug
:app:packageDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareComAndroidSupportTestEspressoEspressoCore222Library UP-TO-DATE
:app:prepareComAndroidSupportTestEspressoEspressoIdlingResource222Library UP-TO-
DATE
:app:prepareComAndroidSupportTestExposedInstrumentationApiPublish05Library UP-TO
-DATE
:app:prepareComAndroidSupportTestRules05Library UP-TO-DATE
:app:prepareComAndroidSupportTestRunner05Library UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE
:app:incrementalDebugAndroidTestJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugAndroidTestJavaWithJavac
:app:compileDebugAndroidTestNdk UP-TO-DATE
:app:compileDebugAndroidTestSources
:app:mergeDebugAndroidTestShaders UP-TO-DATE
:app:compileDebugAndroidTestShaders UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:transformClassesWithDexForDebugAndroidTest
:app:mergeDebugAndroidTestJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebugAndroidTest UP-TO-DATE
:app:processDebugAndroidTestJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebugAndroidTest UP-TO-DATE
:app:validateSigningDebugAndroidTest
:app:packageDebugAndroidTest
:app:assembleDebugAndroidTest
:app:connectedDebugAndroidTest
acme.so35426990.ExampleInstrumentedTest > useAppContext[KFFOWI - 5.1] FAILED
java.lang.AssertionError: failing
at org.junit.Assert.fail(Assert.java:88)
acme.so35426990.ExampleInstrumentedTest > useAppContext[KFFOWI - 5.1.1] FAILED
java.lang.AssertionError: failing
at org.junit.Assert.fail(Assert.java:88)
acme.so35426990.ExampleInstrumentedTest > useAppContext[Nexus 7 - 5.1.1] FAILED
java.lang.AssertionError: failing
at org.junit.Assert.fail(Assert.java:88)
:app:connectedDebugAndroidTes
t FAILEDng 96% > :app:connectedDebugAndroidTest
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///D:/AndroidStudioProjects/
So35426990/app/build/reports/androidTests/connected/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
BUILD FAILED
Total time: 35.227 secs
d:\AndroidStudioProjects\So35426990>
My project has one .zip file in the source code that i want to put in appserver.zip file under folder 1.1.0/deployment. This .zip file again gets bundled in a .tar file.
NOTE: THIS project is not a JAVA/Groovy project i.e. there is no java programs or groovy programs
Following is my build.gradle, which is creating the correct .zip (with correct folder/ source .zip file in it) and .tar file containing the appserver.zip in it:
// Let say $projName, $folderArtifactoryVersion or etc variables used in the following script - are set correctly to a valid value.
task createZipFile( type: Zip) {
// Create artifact directory
def dirName = "build/folderDist"
def dirDist = new File( dirName )
dirDist.mkdirs()
destinationDir dirDist
archiveName "appserver.zip"
println ''
println 'bundleArchiveName: ' + archiveName
into( '1.1.0/deployment' ) {
from( "cognos/Integration/Deployment" )
include( 'SomeCognos_deploy.zip' )
}
}
task createTarFile( type: Zip) {
dependsOn createZipFile
def projName = "dircognosreporting"
def dirParent = "build/folderArts"
// Create artifact directory
def dirName = "$dirParent/com/truven/folder/$projName/$folderArtifactoryVersion"
def dirDist = new File( dirName )
dirDist.mkdirs()
destinationDir dirDist
archiveName "dirCognosReporting-${folderArtifactoryVersion}.tar"
println ''
println 'bundleArchiveName: ' + archiveName
println ''
into( '' ) {
from( "build/folderDist" )
include( 'appserver.zip' )
}
}
build {
dependsOn clean
dependsOn createTarFile
}
Gradle build log shows the following:
-bash-3.2$ /production/gradle/AKS/gradle-1.6/bin/gradle clean build
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "folderArtifactoryVersion" on "root project 'dirCognosReporting'", value: "1.1.0.5".
bundleArchiveName: appserver.zip
bundleArchiveName: dirCognosReporting-1.1.0.5.tar
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain UP-TO-DATE
:findbugsMain UP-TO-DATE
:pmdIntegrationTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:createZipFile
:createTarFile
:build
BUILD SUCCESSFUL
Total time: 5.117 secs
-bash-3.2$
My 2 ?s:
Why the println message defined within createZipFile and createTarFile were printed at the very first stage, even before clean. If I use task build << { ... } then - as expected, i get task build already exist. If I use just build << { .... }, I get a different behaviour.
As build result is giving me what i need under build/folderDist and build/folderArts folders, I'm not much worried about the above bullet at this time, but WHAT should I do, so that I don't see the following lines in the output (as i dont have anything related to java in my source code). Why, gradle is just not doing only - createZipFile, createTarFile and then exit out gracefully?
*
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain UP-TO-DATE
:findbugsMain UP-TO-DATE
:pmdIntegrationTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:createZipFile
:createTarFile
:build
*
ad 1. Because you are printing in the configuration phase, rather than the execution phase. If you want the println statement to be executed as part of executing the task, wrap it with doFirst { ... } or doLast { ... }.
ad 2. Someone (e.g. a parent build script) is applying the java, pmd, checkstyle, and findbugs plugins to this project. Get rid of all that. To nevertheless keep the clean task, apply the base plugin. To keep the build task, declare it yourself (change build { ... } to task build { ... }).
Seems like it's due to the reason as my /init.d folder has a somename.gradle build where I have defined apply plugin: 'java' within allprojects { ..... } section.
If I comment that out, I get an error saying build() ...not there or absent.