I have an Android Studio App that now has close to 100 "productFlavors" associated with it, of course all defined in the build.gradle. I would like to build them from command line since building them one at a time in the IDE would be a nightmare. My issue arises when I run into an error in the middle of building them using the command line gradlew.bat assembleRelease. Once I fix the error I would like to start building at the point of failure (maybe 50 flavors into the build) rather than at the beginning. Is there a way to do that with Gradle? With Ant I was forced to comment them out, I am hoping there is a better way with Gradle since the structure is much more complicated in the file.
UPDATE
I finally went with a solution that encompassed Gradle and Ant (yucky but it works). Basically I wanted to build on of my 100 White Label flavors, with a prefix of the version, and then copy it to the deliver APK without the version. To do this my ANT script looks like:
#!/bin/sh
DEPLOY_DIR=C:/AndroidBuilds/MyCompany.Build
VERSION="63"
NAME="WhiteLabel1"
DEPLOY_FOLDER="whitelabel1"
APK_NAME=$NAME$".apk"
gradlew assemble$NAME
cp $DEPLOY_DIR/$DEPLOY_FOLDER/$VERSION"-"$APK_NAME $DEPLOY_DIR/$DEPLOY_FOLDER/$APK_NAME
NAME="WhiteLabel2"
DEPLOY_FOLDER="whitelabel2"
APK_NAME=$NAME$".apk"
gradlew assemble$NAME
cp $DEPLOY_DIR/$DEPLOY_FOLDER/$VERSION"-"$APK_NAME $DEPLOY_DIR/$DEPLOY_FOLDER/$APK_NAME
This results in 2 APKs being generated, 63-WhiteLabel1.APK and 63-WhiteLabel2.APK, which are then copied to their respective deploy directories as WhiteLabel1.APK and WhiteLabel2.APK
I suppose if you are clever you could make this take parameters to run just the one you want, but Android Studio does a pretty decent job of that.
You can't specifically do that, but you can work around the issue and fix it with some script-magic.
If you have a build type called Release, and a flavor called Iron, you could run:
gradlew.bat assembleIronRelease
So you could write a script that would run through a loop of all flavors, and if it fails, it would tell you which one failed. You can then fix the error, and start the script again, telling it to start at X flavor (you would have to write the logic to tell it where to start though).
Related
Just updated to Android Studio 0.8.2 and I'm suddenly getting ClassNotFoundException on launch for the main activity when one of my apps is built with 0.8.2.
The app is in version control (Git) so I've checked out old builds and they are now exhibiting the same symptom upon execution and they were definitely working just fine when built with 0.8.1.
I've tried clean rebuilds, gradle syncing, manually deleting build/ and, .gradle/ dirs, closing & reopening Android Studio etc. - I've checked out various old builds of my project and tested the APK on several Android devices, the issue is 100% reproducible with both Debug and Release builds.
Strangely, although this is 100% reproducible for this particular project, I have another project which is building and executing just fine.
I've pulled apart the APK that is output from Android Studio 0.8.2 with apktool, and the class is definitely there.
$ pwd
/Users/ben/Development/go-android/Go/build/outputs/apk/Go-debug/smali/au/com/glassechidna/go/content
$ ls
AddTripFragment$1.smali CreateTripFragment$OnQueryTextListener$1.smali CreateTripFragment.smali MainActivity.smali
AddTripFragment.smali CreateTripFragment$OnQueryTextListener.smali GoActivity.smali TrainTimeFragment$1.smali
CreateTripActivity.smali CreateTripFragment$OnSuggestionListener.smali GoApplication.smali TrainTimeFragment.smali
CreateTripFragment$1.smali CreateTripFragment$StopCursor.smali MainActivity$PagerAdapter.smali TripFragment.smali
Stacktrace: https://gist.github.com/Benjamin-Dobell/a77bd8fffb03ddb37ff1
Manifest: https://gist.github.com/Benjamin-Dobell/ca7ee54d7562a0feab0c
Go/build.gradle[1]: https://gist.github.com/Benjamin-Dobell/f9a3a39d6f141e412dac
build.gradle[1]: https://gist.github.com/Benjamin-Dobell/2db744dd89e487325b65
MainActivity.java[2]: https://gist.github.com/Benjamin-Dobell/11a6335f56b6ababeeb4
Any ideas?
[1] Taken from one of the oldest commits, as it has less dependencies etc. cluttering stuff up. However, the issue is still 100% reproducible for this commit.
[2] Just the declaration.
Cleaning from CLI seems to have resolved the issue.
Props to #yogurtearl for pointing me in the right direction.
$ ./gradlew clean
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:Go:clean
BUILD SUCCESSFUL
Total time: 3.906 secs
$ ./gradlew assembleDebug
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:Go:preBuild
:Go:compileDebugNdk
:Go:preDebugBuild
:Go:checkDebugManifest
:Go:preReleaseBuild
:Go:prepareComAndroidSupportSupportV42000Library UP-TO-DATE
:Go:prepareDebugDependencies
:Go:compileDebugAidl
:Go:compileDebugRenderscript
:Go:generateDebugBuildConfig
:Go:generateDebugAssets UP-TO-DATE
:Go:mergeDebugAssets
:Go:generateDebugResValues UP-TO-DATE
:Go:generateDebugResources
:Go:mergeDebugResources
:Go:processDebugManifest
:Go:processDebugResources
:Go:generateDebugSources
:Go:compileDebugJava
:Go:preDexDebug
:Go:dexDebug
:Go:processDebugJavaRes UP-TO-DATE
:Go:validateDebugSigning
:Go:packageDebug
:Go:zipalignDebug
:Go:assembleDebug
BUILD SUCCESSFUL
Total time: 10.64 secs
$ adb uninstall au.com.glassechidna.go.debug
Success
$ adb install Go/build/outputs/apk/Go-debug.apk
8553 KB/s (323343 bytes in 0.036s)
pkg: /data/local/tmp/Go-debug.apk
Success
Update
Since running the gradlew commands above I can now clean and build just fine in Android Studio. Consequently, it would seem that Android Studio wasn't cleaning properly and that manually deleting build/ and .gradle/ directories wasn't sufficient either.
Now, I just need to understand why this worked and why cleaning and building in Android Studio didn't...
If you know about any additional state gradle/gradlew stores elsewhere that could be the culprit, I'd love to hear about it via a comment.
Update 2
This issue has kept occurring for me on my Mac. I've noticed that when I build in Android Studio the "preDexDebug" task generated several warnings as follows:
objc[49452]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Comparing a good APK and a bad one I could see that some of the generated DEX'd classes vary quite significantly between the two APKs. Unfortunately I don't yet know a solution to the problem (I'm stuck building with the Gradle Wrapper from CLI).
I'm trying to build just a phone app from aosp. I've configured my work dir as it was described in google's guide. Then i'm going to my work dir, execute source build/envsetup.sh and get the following:
including device/asus/grouper/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/armv7-a/vendorsetup.sh
including device/moto/wingray/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash
Then i'm executing command mmm packages/apps/Phone/ and something goes wrong, i get
make: Entering directory `/home/build/WORK_DIR'
make: *** No rule to make target `out/target/common/obj/JAVA_LIBRARIES/core_intermediates/javalib.jar', needed by `out/target/common/obj/JAVA_LIBRARIES/com.android.phone.common_intermediates/classes-full-debug.jar'. Stop.
make: Leaving directory `/home/build/WORK_DIR'
Can anyone explain me what should i do? Should i build the whole android project first, or is it a bug in makefile?
Try building the entire source at first...After that whenever you make changes in the source code of any application(in your case Phone), you need to rebuild the entire code. The rebuild process will not take time as only the changes will be built into the system image..Use "make" instead of "mmm" . However don't use "make clean" as it will erase your earlier build and start from scratch. So the outline is:
Execute "make" for building the first time
Make your changes in the application
Execute "make" once again
Use "make snod" if you just want only one component that is built to be attached to the system.img
I'm developing a script to build android project which referencing lib-project so there is some preparations before launching ant, so I decided put that actions into a .bat-file.
The .bat's structure is like the following:
1 - #some preparation actions (moving files, updating properties etc.)
2 - ant debug
3 - #clean everything that was done in the first section
So, the problem is that nothing is executed after the second section - 'ant debug' - though build was successful.
Can anybody shed some light on what am I doing wrong and how to make the script after ant debug-command be executed?
Thanks in advance!
Try the following
...
call ant ...
...
(This is an Android SDK tools v17 problem. Expect a fix in v18)
I have a test target project A, and a tester project B.
Project A has FlurryAgent.jar in its libs folder.
Project B has robotium-solo-3.1.jar in its libs folder
When I compile and run them,
cd A
android update project -p .
cd ..
cd B
android update test-project -p . -m ../A
ant all clean debug
ant uninstall
ant installt
ant test
ant test fails to execute tests:
test:
[echo] Running tests ...
[exec]
[exec] com.example.r17.test.TestOne:
[exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.NoClassDefFoundError
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent
[exec] INSTRUMENTATION_CODE: 0
I've read some posts/questions that solve this problem in Eclipse. But I don't think I can run Eclipse on headless Jenkins slave.
Since this post was the first in search engine results when I entered "java.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent" and my issue was not related to Ant at all, I thought I'd add some info for people who might be scratching their heads after re-installing the ADT.
Basically, in Eclipse when you add an external library in the Java Build Path dialog, don't forget to also switch to the Order and Export tab and tick that library's name in the list. This is needed so that the library is found at run-time, not only at compile time :)
http://code.google.com/p/android/issues/detail?id=27608
I submitted the issue to Google and they uploaded a temporary fix. The fix will also be included in v18 release.
"project member x...#android.com, Today (34 minutes ago)
get the anttasks.jar from the bottom of http://tools.android.com/download to replace the one in your sdk."
The file to replace is at \Android\android-sdk\tools\lib\
It took me a very long time to figure this same problem out when using android-junit-report, but with the help of "adb logcat" I discovered that it wasn't actually missing the instrumentation class that I included, but it was missing its inherited superclass. So I needed to put this back into AndroidManifest.xml:
<application>
<uses-library android:name="android.test.runner" />
</application>
I dont have the rep to comment Qi but I think this may be related to my question here:
VerifyError in android test-project build tools v17
Xav has been instrumental in getting this back up and running and looks like hes got a fix
I have the same case and it doesn't work even if I followed Levon's post. Then I realized I need to copy the FlurryAnalytics.jar into the libs folder in my work space to make it work. Hope this helps.
I have just fix this problem "08-14 08:33:43.398: E/AndroidRuntime(6748): java.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent"
I flow the official web when I want to add the flurry to my android app,it tell me add an external library in the Java Build Path dialog, And then I don't forget to also switch to the Order and Export tab and tick that library's name in the list. This is needed so that the library is found at run-time, not only at compile time,But however it do not works until I just remove the jar from build path,and then copy it to the lib. Done!!!
If I run ant release in the shell in my dir proj it works fine, however, when I try to execute it from python, it fails, why?
/Users/hunterp/proj
Buildfile: /Users/hunterp/proj/build.xml
BUILD FAILED
/Users/hunterp/proj/build.xml:46: sdk.dir is missing. Make sure to generate local.properties using 'android update project'
It is difficult to answer this question without more information about your setup or the code you are using. Particularly the parts that are generating the error since we don't know what your code looks like (either in build.xml or in your python script).
An easy thing to start with, as indicated by #Mark, is to <echo>${basedir}</echo> in your release task to see where exactly it thinks it is running from. My guess is that you are trying to load a properties file or some such and it isn't finding it in an earlier step.
What you can do if the location of ${basedir} looks different when run from within the directory versus within your python script is use a reference to where your build.xml file lives and reference from there:
<dirname property="project.basedir" file="${ant.file.project_name}"/>
Then use use ${project.basedir} instead of ${basedir}.
All of this assuming, of course, that your ${basedir} appears differently between the two. Otherwise I'd need to know more in order to diagnose the issue.