Failing to install dependencies with sdkmanager inside a Dockerfile - android

I'm trying to package the dependencies to build an Android application inside a Docker container. As part of the dependencies installation, I'm using sdkmanager to install some dependencies. When specifying a list of packages to install, it requires to put their names in double quotes. Since also Docker's RUN in exec form requires to put double quotes around its arguments, I'm using double double-quotes and escaping the inner ones like this:
RUN ["./android-sdk/cmdline-tools/bin/sdkmanager", "--sdk_root=/root/android-sdk", "--install", "\"build-tools;33.0.2\"", "\"platform-tools\"", "\"ndk;21.4.7075529\"", "\"cmake;3.6.4111459\""]
However, when I try to build my image I get the following error:
Step 12/20 : RUN ["./android-sdk/cmdline-tools/bin/sdkmanager", "--sdk_root=/root/android-sdk", "--install", "\"build-tools;33.0.2\"", "\"platform-tools\"", "\"ndk;21.4.7075529\"", "\"cmake;3.6.4111459\""]
---> Running in 269b0033b9af
Warning: Failed to find package '"build-tools;33.0.2"'
The command './android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=/root/android-sdk --install "build-tools;33.0.2" "platform-tools" "ndk;21.4.7075529" "cmake;3.6.4111459"' returned a non-zero code: 1
If I instead don't put the double double-quotes, I don't get any errors, but I think it's not installing all the dependencies as later Flutter complains about not finding the Android SDK in the root I specified, and indeed I can't find there e.g. the platform-tools directory. What am I doing wrong? Do you know a better way to install Android SDK inside a container?
You can find the full Dockerfile here.
Thank you for your help.
Update: trying to manually install dependencies witb sdkmanager inside the container, I found out that to install them you first need to manually accept a license agreement and then after installing them flutter still doesn't recognize my installation. Maybe it is too difficult to install the Android SDK inside a container and I should just use this Docker image that runs an sdk from your host or just build the app on my host.

In the end, I solved by basing my image on this one and using the "normal" syntax for run like this:
RUN sdkmanager --install "build-tools;33.0.2" "cmdline-tools;latest" "ndk;21.4.7075529" "platform-tools" "cmake;3.6.4111459"

Related

AAPT2 compile failed: invalid dimen on Android 3.0 Canary 1

I am playing around with Instant Apps for Android.I installed all the correct packages and tired to create new Application with Instant App support (checked the box for Instant App when crating new application). The problem is that I always run into a problem with compile tools. Does anybody else have this problem and was able to find any workaround.
My environment:
Android Studio 3.0 Canary 1
Compile SDK: 25
Build Tools: "26.0.0 rc2"
Gradle plugin:3.0.0-alpha1
Gradle: tried both gradle-4.0-milestone1 and 2
Java 1.8/1.7
OS: tried both Windows 10 and Linux Ubuntu 16.4 LTS
The error:
Error: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.internal.aapt.AaptException: AAPT2 compile failed:
aapt2 compile -o /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/res/merged/androidTest/debug /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml
Issues:
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:520 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:521 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:568 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:594 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:595 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:597 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:598 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:599 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:600 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:601 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:602 invalid dimen
- ERROR: /home/simonp/Work/201705_InstantApp/InstantAppTest/feature/build/intermediates/incremental/mergeDebugAndroidTestResources/merged.dir/values/values.xml:603 invalid dimen
:feature:mergeDebugAndroidTestResources FAILED
The line in question contains (520):
<item format="float" name="abc_disabled_alpha_material_dark" type="dimen">0.30</item>
Hopefully I provided enough information to you to resolve the problem. Thank you.
Below are mentioned four different solutions: A, B, C, and D; pick one that suites you:
A) Fixing Android Studio via Ubuntu .desktop launcher file
This is an Ubuntu-only alternative to the general approach on Fixing Android Studio (see below). Note that you may still want to implement the part about Fixing the shell, and perhaps even revert any modifications to studio.sh to fully confirm this fix.
I got tired of patching my studio.sh for every canary update, so I came up with a better solution that eliminates this step. It works on Ubuntu and simply involves creating a .desktop launcher that sets the sick environment variable in question.
Make a note of where your Android Studio 3 is installed, e.g. ~/opt/android-studio-3.
Prepare your local icon and applications directory, in case the don't already exist:
mkdir -vp ~/.local/share/icons ~/.local/share/applications
Create an Android Studio 3 icon that will make your launcher stand out from the default icon and save it into ~/.local/share/icons/android-studio-3.png. Or you can use the one I made by rubbing a piece of cheese on the original (~/opt/android-studio-3/bin/studio.png):
Create an Android Studio 3 launcher file by copy and pasting this into a shell:
cat <<-EOF > ~/.local/share/applications/android-studio-3.desktop
[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio 3
Icon=android-studio-3
Exec=env LC_NUMERIC="en_US.UTF-8" opt/android-studio-3/bin/studio.sh "%f"
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-studio
EOF
Make it executable:
chmod +x ~/.local/share/applications/android-studio-3.desktop
Now for the tricky part. Ideally you should be able find, start, and create shorts for Android Studio 3 from the Dash:
But personally, I almost always have trouble getting Ubuntu to detect my new or changed .desktop files. One solution is to log out and back in again. If anyone knows how to force a rescan please let me know!
B) Fixing Android Studio start script
Here's an easy, elegant, and semi-permanent fix: Only change the locale of Android Studio itself by modifying its startup script:
Edit studio.sh e.g. ~/opt/android-studio/bin/studio.sh or whatever your installation path may be.
Somewhere at the top of the file, below #!/bin/sh and before the first lines of code appear, add this:
LC_NUMERIC="en_US.UTF-8".
Here's the top part of my studio.sh for completeness:
#!/bin/sh
#
# ---------------------------------------------------------------------
# Android Studio startup script.
# ---------------------------------------------------------------------
#
LC_NUMERIC="en_US.UTF-8"
message()
{
TITLE="Cannot start Android Studio"
...
Restart Android Studio
A note on Upgrading Android Studio or Gradle
When you later upgrade your Android Studio installation, it will detect that you've modified studio.sh. You should let the installer replace the file, and afterwards perform the patch again as described above. Finally restart Android Studio, and you'll be ready again. The other solutions are not affected by this.
C) Fixing the shell; Gradle, Jenkins, all that
Building from the shell using gradlew also requires the fix to be applied. This only affects the shell and not Android Studio. Pick one:
Either specify the the fix on every invocation like this:
LC_NUMERIC="en_US.UTF-8" ./gradlew clean assDebug
Or to make this permanent for the project, edit the gradlew file in the root of the project and somewhere at the top add this:
LC_NUMERIC="en_US.UTF-8"
Like here:
#!/usr/bin/env bash
################################################################################
##
## Gradle start up script for UN*X
##
################################################################################
LC_NUMERIC="en_US.UTF-8"
# Add default JVM options here. You can al...
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
...
Or you can of course also add a global and permanent fix though the use of an alias, gr:
cat <<EOF>>~/.bash_aliases
# Fixing Android Studio 3 Canary bug https://stackoverflow.com/a/44304075/2412477
alias gr='LC_NUMERIC="en_US.UTF-8" ./gradlew'
EOF
Note this is how bash shell aliases are added on Ubuntu; if you're on a different OS perhaps you should append to ~/.bashrc or ~/.profile instead.
Then start a new shell and now instead of invoking ./gradlew use the new alias gr:
gr clean assDebug
The clear disadvantage of #2 is that this has to be applied to all projects manually. The advantage, I think, is that this will automatically be overwritten when a new gradlew is installed, much like studio.sh gets replaced, so you get to test if the bug has been fixed =)
D) Disabling APPT2 all together
Personally I wouldn't do this, but I've added it for completeness since it definitely is a way to make appt2 stop giving errors. Add this line to your gradle.properties: android.enableAapt2=false
The workaround is to switch your development machine to a locale which uses "." as a decimal mark.
It can be changed the following way:
I solved this problem by adding the following line to the gradle.properties files
android.enableAapt2=false
This issue has been fixed in the newest Android Studio stable. Upgrading your Android Studio to 3.0 should solve this issue for you (also no need to disable AAPT2).
Make sure you are not adding any units(dp) when using format="float"
I was facing the same problem because I auto-generated dimens using Android Studio using Extract dimen resource and it added unit type like:
<item name="margin_top" type="dimen" format="float">51.75dp</item>
It should be:
<item name="margin_top" type="dimen" format="float">51.75</item>
add
maven{
url 'https://maven.google.com'
}
to repositories work for me
Required libraries for 64-bit machines:
If you are running a 64-bit version of Ubuntu, you need to install some 32-bit libraries with the following command:
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
If you are running 64-bit Fedora, the command is:
sudo yum install zlib.i686 ncurses-libs.i686 bzip2-libs.i686

How to build v4 support library from source

I'm trying to build the v4 support library from source sice I modified a portion of the library. I'm trying to do this on ubuntu 13.10 with gradle. I followed the instructions in this answer, but now I'm stuck. I used gradle 1.10 with ubuntu since when I tried to build it on windows, it said windows wasn't supported and on ubuntu with gradle 2.4 it said gradle 1.10 was the version that was supported. When I try building with
gradle clean jar --stacktrace
I keep getting an IllegalStateException: llvm-rs-cc is missing, this is a portion of the the stack trace which I keep getting
Caused by: java.lang.IllegalStateException: llvm-rs-cc is missing
at com.android.builder.AndroidBuilder.compileAllRenderscriptFiles(AndroidBuilder.java:1281)
at com.android.builder.AndroidBuilder$compileAllRenderscriptFiles.call(Unknown Source)
at com.android.build.gradle.tasks.RenderscriptCompile.taskAction(RenderscriptCompile.groovy:99)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
The whole stacktrace is here
I tried looking through the source code at AndroidBuilder.java and that hasn't shed any light.
I even tried copying the said llvm-rs-cc file from android-sdk-linux/build-tools to as many folders as I could. I've added the the path to the llvm-rs-cc binary to my path as like the comment in BuildToolInfo.java and also the path to build-tools, tools, and platform-tools which I believe I downloaded using the android sdk manager. I confirmed that the path were added using the printenv command after restarting.
What am I doing wrong?
It turns out that that that I needed to edit the local.properties file in plaform/frameworks/support to add the sdk directory, i.e
sdk.dir=/path/to/android-sdk-linux/
Adding this actually made the whole llvm-rs-cc shenenigans disappear but... there's more
The stackoverflow answer that I was following said to use this command
platform\frameworks\support\v4\gradle clean jar
which I interpreted to mean navigate to the v4 directory then call gradle with
gradle clean jar
Here are the *complete steps I followed in case anybody wants to built the support library also.
First, follow the instructions in this answer:
You need to checkout additional repositories from
https://android.googlesource.com:
platform/frameworks/support
platform/prebuilts/gradle-plugin
platform/prebuilts/maven_repo/android
platform/prebuilts/sdk
platform/prebuilts/tools
Please, keep the directory structure as in android repository.
Install the packages lib32stdc++6 and lib32z1, I used apt-get
sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1
Download the android sdk from the android developer website here
Unpack the archive to any location then navigate to it then to tools\
run ./android this should lainch the sdk manager then download these packafes if they're not already downloaded
All android api from api 4 to api 22 (You may need to show obsolete packages).
Build tools 19.01 (You may need to show obsolete packages) and the most recent build tools
Most recent Platform tools
Most recent SDK tools
Normally this should be sufficient to build the support library with gradle, but it turns out that the jar file in the git repository for api 22 is actually not up to date as it doesn't contain the new AccessibilityInfo methods that were added in api 22, yes I decompiled it to be sure. So a few more steps.
Replace the andoid.jar file in platform/prebuilts/sdk/current that you downloaded from the git repository with the one from android-sdk-linux/platforms/android-22/
We're almost done here but two more issues. If you try to build the library now there'll be two compiltion errors in Fragment.java and in FragmentActivity.java feel free to fix these however you like, since I'm not sure how correct my fix for these were.
To fix these, in Fragment.java on line #935 I added a cast so
result.setFactory(mChildFragmentManager.getLayoutInflaterFactory());
became this
result.setFactory((LayoutInflater.Factory)mChildFragmentManager.getLayoutInflaterFactory());
For the other fix, in FragmentActivity.java on line #299 I replaced
final View v = mFragments.onCreateView(name, context, attrs);
with this
final View v = mFragments.onCreateView(null, name, context, attrs);
The reason for adding the null there was because in the previous versions the first parameter, which is View parent didn't exist and in the onCrateView method parent was declared and initialized to null.
The resulting jar file can be found in platform/out/host/gradle/frameworks/support/support-v4/build/libs/
*Some steps may be missing, as this process took me a long time, and I may have forgotten some things I did.
Try this:
compile files('libs/your.jar')
eclipse help linkv4 support library help for building gradle

Titanium Mobile: Cannot build android modules in 3.3.0

Update: To clarify, I can build the process successfully. The question is about installing the example project directly on a device (though I'm thinking emulator won't work either).
I developed a module about two years ago that allowed bluetooth connectivity on Android. I believe the latest version of the Titanium SDK at the time was around 2.0. I believe the specifics of the module and the example app are irrelevant to this question. I will ask my question first, and then try and explain the steps that I have gone through to lead me to the actual question.
My question is: is something in my environment misconfigured, or is this a bug in the Titanium SDK?
If it is the latter, I am very surprised that I can't find any information about it, since it prevents android modules from installing with ant in the latest SDK.
Information about my build environment:
Mac OS 10.9.5
Titanium Studio 3.3.0.GA
Ti CLI 3.3.0
Android 19
java -version: java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
I am trying to build it now for the latest SDK, 3.3.0 at the time of this writing. I found that when I tried to build (install) with ant, it resulted in the following output:
[exec] [ERROR] /var/folders/x7/h7lgzf1n4nx7fcwr26fdrzxr0000gn/T/mTUYC62ti/testmodule/build/android/res/values-v14/themes_base.xml:133: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
[exec] [ERROR] /var/folders/x7/h7lgzf1n4nx7fcwr26fdrzxr0000gn/T/mTUYC62ti/testmodule/build/android/res/values-v14/themes_base.xml:148: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light.DialogWhenLarge'.
[exec] [ERROR] /var/folders/x7/h7lgzf1n4nx7fcwr26fdrzxr0000gn/T/mTUYC62ti/testmodule/build/android/res/values-v14/themes_base.xml:159: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
[exec] [ERROR] Error generating R.java from manifest
[exec] [ERROR] Build Failed.
BUILD SUCCESSFUL
Total time: 20 seconds
Not only that, but when creating a brand new mobile module project, and building straightaway with ant:
cd proj/android && ant install
The errors are the same. I should also point out that I reformatted not too long ago, so I find it unlikely that I have borked my titanium installation already. Now, from here, I've gotten into the Titanium build scripts to try and figure out what is happening. First, from the Titanium SDK 3.3.0 release notes:
Due to the addition of the appcompat library, there are a number of behavior changes to the application:
...
The target SDK must be set to API level 14 (Android 4.0.x) or higher, or you must have API level 14 or higher installed.
Now in the build output for my project:
[exec] [TRACE] Writing out AndroidManifest.xml
[exec] [DEBUG] /path/to/my/androidsdk/build-tools/17.0.0/aapt package -m -J /var/folders/x7/h7lgzf1n4nx7fcwr26fdrzxr0000gn/T/mTUYC62ti/testmodule/build/android/gen -M /var/folders/x7/h7lgzf1n4nx7fcwr26fdrzxr0000gn/T/mTUYC62ti/testmodule/build/android/AndroidManifest.xml -S /var/folders/x7/h7lgzf1n4nx7fcwr26fdrzxr0000gn/T/mTUYC62ti/testmodule/build/android/res -I /path/to/my/androidsdk/platforms/android-10/android.jar
Note that it's using the tools for android-10 and not android-14+ which is strange considering the relevant bits of my timodule.xml and build.properties:
timodule.xml:
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
<tool-api-level>19</tool-api-level><!-- deprecated - see below -->
build.properties:
titanium.platform=/Users/trey/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.GA/android
android.platform=/Users/trey/sdk/android-sdk-macosx/platforms/android-19
google.apis=/Users/trey/sdk/android-sdk-macosx/add-ons/addon-google_apis-google-19
android.ndk=/Users/trey/sdk/android-ndk-r9d
As it turns out, it seems to be only the deprecated element that matters, and not in timodule.xml at all. Build scripts are found at $titanium_sdk/$os/$version/android/
Observation: Setting MIN_API_LEVEL = 19 (or 14) instead of 10 in builder.py fixes the issue. So the build script is ignoring my configuration and using the default. This seems to happen in the init method of the builder class:
temp_tiapp = TiAppXML(self.project_tiappxml)
if temp_tiapp and temp_tiapp.android:
if 'tool-api-level' in temp_tiapp.android:
self.tool_api_level = int(temp_tiapp.android['tool-api-level'])
tool_api_level_explicit = True
This sets the tool_api_level that the build script uses, but in my case it never gets called because there is not tiapp.xml. So I made a tiapp.xml, and put it in my example project. It has the same configs as the timodule.xml. As part of the build process this gets copied along with the rest of the example project into a temp folder that will be used to build and run the project. self.project_tiappxml in the code above is the root of the project. And there is still no tiapp.xml there, because it was copied to the Resources directory with everything else, so tool_api_level always gets set to the default of 10. That is basically as far as I've gotten.
So, again my question: is my configuration wrong, or is this a bug. It seems to me that if it is a bug, then no one would be able to build android modules, best I can tell. So if it's my fault, what have I done to cause it, and how can I fix it.
Update: If you saw my last edit, that was wrong and I'm sorry - my selected SDK for ti was 3.2.3! Fixed that and it creates the new project fine. It also builds. However, installing the example project still results in the same error as above:
[exec] [ERROR] Error generating R.java from manifest
[exec] [ERROR] Build Failed.
I also added a line above the call to aapt, to clarify that these errors occur while trying to write AndroidManifest.xml for the example project.
Its good you are working with 3.3.0, because from this version Android module creation is relatively easy.by viewing your build.properties i think something is missing or you forgot to add completely here it should be something close to :
titanium.platform=/Users/xxxxxx/Library/Application Support/Titanium/mobilesdk/osx/3.3.0.GA/android
android.platform=/Users/xxxxxx/Documents/adt-bundle-mac/sdk/platforms/android-16
google.apis=/Users/xxxxxx/Documents/adt-bundle-mac/sdk/add-ons/addon-google_apis-google-16
android.ndk=/Users/xxxxxx/Documents/android-ndk
but what i would suggest is check the following things as they get missed often:
you should have android-ndk installed and in the path
you must have gperf installed with your system(for mac comes with xcode command line tools)
Followed by running the following command in your terminal:
ti create -p android -t module -d <WORKSPACE_DIR> -n <MODULE_NAME> -u <MODULE_URL> --id <MODULE_ID>
## Sample Command
ti create -p android -t module -d ~/Documents/Sample_Workspace/ -n calc -u http:// --id org.appcelerator.calc
If everything is alright you will have a module in your Sample_Workspace folder with name calcand the given id.
you can work on it directly by importing it to your eclipse. and once done can build it using ant over the directory.
Hope it helps. Check the module creation guide.

getting error during project creation using phonegap-2.5.0

i have installed android sdk and downloaded the latest version of phonegap 2.5.0 in fedora 18.
i am trying to create a project using the following command
./create ~/Desktop/android-project com.example.android android_project
am getting the following error.
which: no android in (/sbin:/bin:/usr/sbin:/usr/bin)
An unexpected error occurred: ANDROID_BIN="${ANDROID_BIN:=$( which android )}" exited with 1
need your valuable suggestions.
finally found the answer
After checking my .bash_profile paths, and a bunch of digging, I finally found the cause of the issue. If you open up the create file (phonegap-2.5.0/lib/android/bin/create), there is a line that lists ANDROID_BIN=”${ANDROID_BIN:=$( which android )}”. The “which android” is the cause of the issue (or at least it seemed to be in my case). If you replace this line with the full path to your android tools (as listed below) it should resolve the issue. My final line looked like this:
ANDROID_BIN=/Users/ktyacke/DEV/adt-bundle-mac-x86_64-20130219/sdk/tools/android
The message you have means the phonegap script cannot find the android binary, which is included in the SDK you downloaded. Add the binary's directory, as well as the android tool's directory, to your path defined in ~/.bash_profile or any other location you're initializing the shell's environment variables.

NoClassDefFoundError when running Instrumentation test with 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!!!

Categories

Resources