Android CI using Bitbucket Pipelines and Docker - android

I am trying to set up Continuous Integration (CI) in Bitbucket Pipelines for Android.
I have created a sample blank activity using Android Studio 2.1.1.
With Pipelines I'm using the uber/android-build-environment Docker container which creates the environment nicely. Here is my bitbucket-pipelines.yml
image: uber/android-build-environment:latest
pipelines:
default:
- step:
script:
- echo y | android update sdk --filter "extra-android-m2repository" --no-ui -a # Grab the Android Support Repo which isn't included in the container
- ./gradlew assembleDebug
Some changes are needed since uber/android-build-environment is expecting to be run like so:
docker run -i -v $PWD:/project -t uber/android-build-environment /bin/bash /project/ci/build.sh
For example, the source is not copied to the volume /project but instead Pipelines copies the contents of the Bitbucket repo to the working directory of the container at:
/opt/atlassian/bitbucketci/agent/build
And when ./gradlew assembleDebug is run I get the following error:
...
FAILURE: Build failed with an exception.
* What went wrong:
Could not create service of type TaskArtifactStateCacheAccess using TaskExecutionServices.createCacheAccess().
> Failed to create parent directory '/opt/atlassian/bitbucketci/agent/build/.gradle' when creating directory '/opt/atlassian/bitbucketci/agent/build/.gradle/2.10/taskArtifacts'
* 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: 56.449 secs
Running ls -al in the working directory gives:
ls -al
total 52
drwxr-xr-x 5 root root 4096 May 31 22:33 .
drwxr-xr-x 3 root root 4096 May 31 22:43 ..
drwxr-xr-x 3 root root 4096 May 31 22:33 app
-rw-r--r-- 1 root root 462 May 31 22:33 bitbucket-pipelines.yml
-rw-r--r-- 1 root root 498 May 31 22:33 build.gradle
drwxr-xr-x 8 root root 4096 May 31 22:33 .git
-rw-r--r-- 1 root root 387 May 31 22:33 .gitignore
drwxr-xr-x 3 root root 4096 May 31 22:33 gradle
-rw-r--r-- 1 root root 855 May 31 22:33 gradle.properties
-rwxr-xr-x 1 root root 4971 May 31 22:33 gradlew
-rw-r--r-- 1 root root 2314 May 31 22:33 gradlew.bat
-rw-r--r-- 1 root root 15 May 31 22:33 settings.gradle

It's a bug in their system , I report it(issue url, it's quite long) to them and they have fixed it (fix url).I have tested on my project and it successfully build.Try to build your project now and good luck.

It looks like uber/android-build-environment is not supported anymore.
I ended up using javiersantos/android-ci instead which works perfectly from scratch.
Just add the following content to bitbucket-pipeline.yml:
image: javiersantos/android-ci:27.0.3
pipelines:
default:
- step:
script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x ./gradlew
- ./gradlew assembleDebug

Could you symlink your project from /opt/atlassian/bitbucketci/agent/build to /project from within the container? ln -s /opt/atlassian/bitbucketci/agent/build /project is the command you'll need.
or alternatively copy the files to the new path?
I have no experience with android development, so YMMV :)

Related

Managing files in Android terminal

Using a terminal emulator in my android phone I accidentally copied /proc directory into another user directory. Now I want to delete the copy but I don't have the permissions to do so. I tried to change ownership and permissions to 777 but with no success. I am using Oneplus 2 and termux application. Any suggestions?
Edit:
The original /proc directory :
dr-xr-xr-x 459 root root 0 Jan 1 1970 proc/
it was copied to /.../line/proc:
Line:
drwxrwxrwx 4 u0_a45 u0_a45 4096 Oct 17 12:23 line/
Line/proc:
dr-xr-xr-x 52 u0_a45 u0_a45 4096 Jan 1 1970
proc/
The new proc directories are not removable:
rm -rf line/proc
rm: can't remove 'line/proc/12159/task/12247': Permission denied
...

How to build -debug-androidTest-unaligned.apk in gradle task

in android studio, when i run espresso test, console output:
Installing APK: /home/roroco/Dropbox/jvs/ro-adr/testStartApp/build/outputs/apk/testStartApp-debug-androidTest-unaligned.apk
Uploading file to: /data/local/tmp/ro.testStartApp.test
Installing ro.testStartApp.test
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/ro.testStartApp.test"
pkg: /data/local/tmp/ro.testStartApp.test
Success
but when i rm build/ and run gradle assembleDebug, the "testStartApp-debug-androidTest-unaligned.apk" doesn't exist like following:
roroco#roroco ~/Dropbox/jvs/ro-adr/testStartApp $ lsa /home/roroco/Dropbox/jvs/ro-adr/testStartApp/build/outputs/apk
total 9496
drwxr-xr-x 2 roroco roroco 4096 May 21 23:08 .
drwxr-xr-x 6 roroco roroco 4096 May 21 23:40 ..
-rw-r--r-- 1 roroco roroco 3237948 May 21 23:08 testStartApp-debug.apk
-rw-r--r-- 1 roroco roroco 3237559 May 21 23:08 testStartApp-debug-unaligned.apk
-rw-r--r-- 1 roroco roroco 3211410 May 21 23:08 testStartApp-release-unsigned.apk
which gradle task can generate "testStartApp-debug-androidTest-unaligned.apk"?
When I list tasks:
roroco#roroco ~/Dropbox/jvs/ro-adr/testStartApp $ gd tasks|gr assemble
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleRelease - Assembles all Release builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
it's assembleAndroidTest

zipalign: error while loading shared libraries: libc++.so: cannot open shared object file: No such file or directory

I am trying to build android app. When I run the zip align tool to optimize the APK, I get this error message:
zipalign: error while loading shared libraries: libc++.so: cannot open shared object file: No such file or directory
I tried to install libc++
sudo aptitude install libc++
it says: Couldn't find package "libc+".
Snapshot of my terminal
If your system is 64-bits, there should be a folder lib64 on the path of
[android-path]/build-tools/[version]/
The files in lib64 are
[ec2-user 25.0.2]$ ll lib64/
total 51628
-rwxrwxrwx 1 ec2-user ec2-user 30712616 Dec 23 07:22 libLLVM.so
-rwxrwxrwx 1 ec2-user ec2-user 482522 Dec 23 07:22 libbcc.so
-rwxrwxrwx 1 ec2-user ec2-user 433914 Dec 23 07:22 libbcinfo.so
-rwxrwxrwx 1 ec2-user ec2-user 1211614 Dec 23 07:22 libc++.so
-rwxrwxrwx 1 ec2-user ec2-user 20019608 Dec 23 07:22 libclang.so
Just copy the folder lib64 and zipalign program together to the destination path, and you can run the zipalign correctly. It worked for me. I guess the zipalign has a dependency on the files in lib64 folder.
I met the same problems and google it. You can try the following suggestions:
If you are in 64-bit environment, try: sudo apt-get install lib32stdc++6 lib32z1 lib32z1-dev.
Update the latest android sdk tools and do not move the zipalign binary to any other folder. It solve my problem.
I had the exact same problem and it was probably because I moved the zipalign binary from <android-path>/build-tools/23.0.3 to <android-path>/tools.
The solution is to add the build-tools/23.0.3 dir to your path:
export PATH=${PATH}:<android-path>/build-tools/23.0.3

Gradle Error 2 in Android project even file exists

I've generated android project with gradle support in IntelliJ. I have arch linux, on my friend's computer who has Windows everything is ok. On my computer I cannot build project, I get following error:
Error:Gradle: Execution failed for task ':app:mergeDebugResources'.
/home/hubert/IdeaProjects/AGHacks/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/drawable-xhdpi/abc_list_selector_disabled_holo_light.9.png: Error: Cannot run program "/home/hubert/bin/android-sdk/android-sdk-linux/build-tools/21.0.1/aapt": error=2, No such file or directory
And both file exists:
➜ IdeaProjects ls -al /home/hubert/IdeaProjects/AGHacks/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/drawable-xhdpi/abc_list_selector_disabled_holo_light.9.png
-rw-r--r-- 1 hubert hubert 188 Oct 22 22:51 /home/hubert/IdeaProjects/AGHacks/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/drawable-xhdpi/abc_list_selector_disabled_holo_light.9.png
➜ IdeaProjects ls -al /home/hubert/bin/android-sdk/android-sdk-linux/build-tools/21.0.1/aapt
-rwxrwxrwx 1 hubert hubert 1248409 Oct 21 21:29 /home/hubert/bin/android-sdk/android-sdk-linux/build-tools/21.0.1/aapt`
What am I doing wrong?
I needed to install 32bit version of libc++ and other applications.

Unable to locate tools.jar Fedora

I'm trying to compile my python game to run on android using PGS4A and I'm getting this error
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.7.0-openjdk- 1.7.0.60-2.4.7.0.fc20.x86_64/lib/tools.jar
There are a bunch of solutions for this on Windows but I can't find one for fedora.
I have the /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.x86_64/ but nothing else
Assuming you are using the Java that comes packaged with Fedora (some version of OpenJDK) you probably need to install the appropriate -devel package.
Here's an example of what you would do on my Fedora 20 workstation:
$ rpm -qa|grep openjdk
java-1.7.0-openjdk-headless-1.7.0.60-2.4.7.0.fc20.x86_64
java-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.x86_64
$ sudo yum install java-1.7.0-openjdk-devel
...
The first command tells me what Java I'm using (1.7.0, since 1.8.0 is another option) and the second command asks it to install the development libraries, which includes tools.jar, among other things.
But I should add that my /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.x86_64 directory does contain a few things:
-r--r--r--. 1 root root 172252 Apr 16 02:58 THIRD_PARTY_README
-r--r--r--. 1 root root 19263 Apr 16 02:58 LICENSE
-r--r--r--. 1 root root 1503 Apr 16 02:58 ASSEMBLY_EXCEPTION
drwxr-xr-x. 3 root root 4096 Apr 20 19:09 jre-abrt
drwxr-xr-x. 4 root root 4096 Apr 20 19:09 jre

Categories

Resources