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

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

Related

index.android.bundle missing in APK after upgrading to RN 0.68

After upgrading our RN app to RN 0.68, we are getting errors with the release build:
FATAL EXCEPTION: create_react_context
Process: com.app, PID: 15057
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
The app works fine in development, and was fine before upgrading. It is using Hermes, but not using the new Fabric architecture.
When building the APK and then looking into its content, we can see that the bundle is not copied. But it is correctly built in the intermediate artifacts:
$ ./gradlew assembleRelease
…
BUILD SUCCESSFUL in 45s
1050 actionable tasks: 14 executed, 1036 up-to-date
$ unzip -l app/build/outputs/apk/release/app-arm64-v8a-release.apk | grep bundle
<nothing>
$ ls -l app/build/outputs/apk/release/app-arm64-v8a-release.apk
-rw-r--r-- 1 renchap staff 15618010 Apr 12 21:03 app/build/outputs/apk/release/app-arm64-v8a-release.apk
$ find . -name "index.android.bundle"
./app/build/generated/assets/react/release/index.android.bundle
./app/build/intermediates/merged_assets/release/out/index.android.bundle
./app/build/intermediates/merged_assets/release/mergeReleaseAssets/out/index.android.bundle
./app/build/intermediates/assets/release/index.android.bundle
$ ls -lh ./app/build/intermediates/assets/release/index.android.bundle
-rw-r--r-- 1 renchap staff 11M Apr 12 19:48 ./app/build/intermediates/assets/release/index.android.bundle
I am suspecting that there is a missing build step and it is not copied to the final directory, but I am not familiar enough with Gradle or RN's build process to check this.
Do you have any idea of what can cause this, or where to look at to troubleshoot this?
Found it after comparing the build files with a brand new RN app!
I had
classpath("com.android.tools.build:gradle:7.1.2")
in android/build.gradle
But with RN 0.68, you need to depend exactly on version 7.0.4, otherwise the JS bundle is not copied into the final APK.
The release APK is now working after switching to
classpath("com.android.tools.build:gradle:7.0.4")

Android CI using Bitbucket Pipelines and Docker

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 :)

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

Build Android project on command line on OSX: Task 'assembleDebug' not found in root project

I'm trying to build Android projects on the OSX (Mavericks 10.9.5) command line using this how-to: http://developer.android.com/tools/building/building-cmdline.html.
This How-To explains the use of assembleDebug/assembleRelease to build an Android project.
Unfortunately gradle doesn't create the assembleDebug or assembleRelease targets.
Executing ./gradlew assembleDebug returns this:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'assembleDebug' not found in root project 'test'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.826 secs
Steps:
android create project
The test project has been created with android create project --path . --name "DummyAPK" --target android-21 --package com.dummyapk.dummyapk --activity DummyActivity
which returned
Created directory /Users/user/Documents/test/src/com/dummyapk/dummyapk
Added file ./src/com/dummyapk/dummyapk/DummyActivity.java
Created directory /Users/user/Documents/test/res
Created directory /Users/user/Documents/test/bin
Created directory /Users/user/Documents/test/libs
Created directory /Users/user/Documents/test/res/values
Added file ./res/values/strings.xml
Created directory /Users/user/Documents/test/res/layout
Added file ./res/layout/main.xml
Created directory /Users/user/Documents/test/res/drawable-xhdpi
Created directory /Users/user/Documents/test/res/drawable-hdpi
Created directory /Users/user/Documents/test/res/drawable-mdpi
Created directory /Users/user/Documents/test/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt
gradle init
After that I executed gradle init, which returned
:wrapper
:init
BUILD SUCCESSFUL
gradlew tasks
Querying the available tasks with gradlew tasks returns (isn't there missing something?)
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'test'. [incubating]
dependencies - Displays all dependencies declared in root project 'test'.
dependencyInsight - Displays the insight into a specific dependency in root project 'test'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'test'.
properties - Displays the properties of root project 'test'.
tasks - Displays the tasks runnable from root project 'test'.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.474 secs
My Java version is
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
..and Gradle version (installed via brew) is
------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_60 (Oracle Corporation 24.60-b09)
OS: Mac OS X 10.9.5 x86_64
What am I missing to be able to build an Android project on the command line?
android create project does not create a gradle friendly structure. It creates an ant friendly structure. You have two options depending on your intentions.
use ant to build your project ( not currently supported by Android team )
use Android Studio to generate a gradle friendly project structure.
num 2 is the recommended approach by the Android team. It's as simple as dl'ing Android Studio and creating a new project. From there you should be able to create a new project that can be built with ./gradlew build
try This:
./android create project -p AppPAKTGV -a Main -k com.example.apppaktgv -t android-23 -g -v 0.11.+
it's works but when i try target 24 or 25 not work i don't now
Try to do this and note
a) you need to type tools/android under Step 3 (like step 2: Execute)
-- but as said the ant structure is not helpful
-- not sure I can go from there
b) I follow the advice and also ensure get the platform-tools
-- I can build
-- I can get that .apk
-- I can adb install (I rename any existing .apk)
Seems working!

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.

Categories

Resources