How to build Expo APK local - android

Is it possible to build the APK of an expo app locally?
The doc says:
If you haven’t used exp before, the first thing you’ll need to do is login with your Expo account using exp login.
I tried exp start, exp build:android but the commands require a login.
I don't want to build the APK using expo server. Is there a way to run this build locally? So no login and push of source code required?
If not, can I view the whole source code of the generated APK?

New to the party, so guessing this wasn't available at the time of the post - Instructions for building expo apps locally:
Building Standalone Apps on Your CI
Update Jan, 2023:
You may want to check out the updated version:
This doc was archived in August 2022 and will not receive any further updates. SDK 46 is the last SDK supported by Classic Builds and the Classic Build service will stop running for all SDK versions after January 4, 2023. Check out Running builds on your own infrastructure and Triggering builds from CI.

if you want to generate apk eject the CRNA with npm run eject command. Then you will get android and ios folders suppurate in mac and you will get an only android folder in windows. and follow the instruction which is in a given link below
"https://facebook.github.io/react-native/docs/signed-apk-android.html"

I've straggled with similar issue, I managed to solve it following several steps found on the web, and tweaking a bit:
https://forums.expo.io/t/expokit-full-local-build-without-publish-android/31400/2
Run the https server your machine, note that the server must have a certificate since it is a HTTPS server (I used port 4443), but it does not need to be trusted by your machine - it works anyway (I found it easy to use: https://gist.github.com/dergachev/7028596 - Python 2.7,
https://gist.github.com/dergachev/7028596#gistcomment-1989299 - Python 3.X)
Go to your Expo project folder, make sure there is no dist
folder in it; alternatively you can provide dist path with the --output-dir flag
(the react-native bundle and assets will be generated to it).
Open command line and run:
expo export -t bare --dev --public-url https://localhost:4443/, once done you will have the android bundle and assets in the output-dir (default - dist)
Copy the android bundle from dist/bundles/android-<bunch of numbers (MD5)>.js to <YourExpoProjectFolder>/android/app/src/main/assets/index.android.bundle and to <YourExpoProjectFolder>/android/app/build/generated/assets/react/release/index.android.bundle (note: the name of the bundle must be index.android.bundle)
In /dist/bundles/assets you'll have your assets files, but they would be named as their MD5 value, copy each of them to <YourExpoProjectFolder>/android/app/src/main/assets/, but add the asset_ prefix and .<ext> for each. e.g. for a PNG image file with MD5 value of de57a0c7a3a23aabcaceaf1185b1e79e:
copy <YourExpoProjectFolder>/dist/bundles/assets/de57a0c7a3a23aabcaceaf1185b1e79e <YourExpoProjectFolder>/android/app/src/main/assets/asset_de57a0c7a3a23aabcaceaf1185b1e79e.png
cd android
gradlew.bat assemble
expo diagnostics output:
Expo CLI 3.18.6 environment info:
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 12.16.2
Yarn: 1.22.0
npm: 6.14.4
npmPackages:
expo: ~37.0.3 => 37.0.8
react: ~16.9.0 => 16.9.0
react-native: ~0.61.5 => 0.61.5
react-navigation: ^4.3.9 => 4.3.9

If you want to build the app locally without using the turtle CLI of expo, you can build it just how you would build a normal react native app
But beware that you will have to touch some native android code (gradle only)
But only one or two files....
Steps:
Generate a release Keystore by keytool
Link the keystore in build.gradle file
Run cd android && ./gradlew assembleRelease to build the apk
Check out this post to follow these steps in detail

Motivation: build local, test performance of release build on a real device.
Environment: Expo SDK 46 managed project, on AlmaLinux 8.6 (ymmv)
Caution:
I keep a copy of my entire project dir in case things get messed up:
cd <project *parent* dir>
\cp -far <project dir name> <project dir name>.bak
and update that when appropriate with
cd <project dir> # if not there
rsync -atvi --delete . ../<project dir name>.bak/
Steps to create android project dirs/files and a debug build apk :
cd <project dir>
npx expo run:android # not the same as "npm run android"
see ref in official expo docs here
release build:
cd <projectDir>/android/app
keytool -genkey -v -keystore <projectName>.keystore -alias <<projectName>> -keyalg RSA -keysize 2048 -validity 10000
ammend android/app/build.gradle file - see details here but do not use the build instructions (atow). Then ...
cd ../../ # to project dir
npx expo run:android --no-install --no-bundler --variant release
(although tbh I'm guessing for now that --no-bundler is to do with the Metro server)
You should find a release apk in
<project dir>/android/app/build/outputs/apk/release
Note this includes full expo and the build can take quite a while. It took more than 12 mins on the following:
Operating System: AlmaLinux 8.6
KDE Plasma Version: 5.23.3
KDE Frameworks Version: 5.88.0
Qt Version: 5.15.2
Kernel Version: 4.18.0-372.32.1.el8_6.x86_64 (64-bit)
Graphics Platform: X11
Processors: 12 × Intel® Xeon® CPU E5-2620 v3 # 2.40GHz
Memory: 31.1 GiB of RAM
Graphics Processor: AMD CEDAR
You can reduce build time and the final apk size by going for an expo development build or moving your code to a porn project (plain old react-native) :-)

Related

"ENOENT: no such file or directory" when building Android project in AWS CodeBuild and sending artifact to Visual Studio AppCenter

I have an android project that i build with AWS CodeBuild. The project is built successfully, the .apk is stored in s3 bucket with no problem. Now, I'm also trying to upload that .apk to Visual Studio App Center, but when i run the CodeBuild project, I get this error
Error: Command 'distribute release --app Test/Android-Test --file SourceCode/MobileApp/android/app/build/outputs/apk/release/app-release.apk --group test' failed with exception "ENOENT: no such file or directory, stat 'SourceCode/MobileApp/android/app/build/outputs/apk/release/app-release.apk'"
Here is my buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
android: 29
java: corretto8
nodejs: 12
pre_build:
commands:
- cd SourceCode/MobileApp
- npm install -g react-native-cli
- yarn
- cd android
build:
commands:
- ./gradlew clean
- ./gradlew assembleRelease
post_build:
commands:
- npm install -g appcenter-cli
- appcenter login --token tokenhere12345
- appcenter apps list
- appcenter distribute release --app Test/Android-Test --file SourceCode/MobileApp/android/app/build/outputs/apk/release/app-release.apk --group "test"
artifacts:
files:
- SourceCode/MobileApp/android/app/build/outputs/apk/release/*.apk
discard-paths: yes
Now, you might be wondering, maybe I put the wrong path? Well no because on the artifactsblock, i can upload my .APK to s3 bucket with no problem, that is why I know the path is correct, otherwise it would reject it. I suspect that the path (in the app center distribute command) needs to be formatted, but I'm not sure if that is the case as Microsoft and AppCenter docs do not mention any format for the path. Anyone know what am I missing? TIA!

Signed Apk not found in directory React Native - Android

I am using react-native 0.60 version and my Gradle version is 5.4.1. Now I'm trying to extract signed apk. When I execute, all the steps the apk build successfully. But When I checking this path F:\React Native\AwesomeProject1\android\app\build\outputs\apk
please check this screenshot https://prnt.sc/p391mr.
Use this command to generate release apk
react-native run-android --variant=release
 Note that --variant=release is only available if you've set up signing as described above.
You can kill any running packager instances, since all your framework and JavaScript code is bundled in the APK's assets.
Please follow this link
https://facebook.github.io/react-native/docs/signed-apk-android
You using this command
$ cd android
$ ./gradlew bundleRelease
You only generate android apk bundle (AAB)not an apk.The generated AAB can be found under 
android/app/build/outputs/bundle/release/app.aab
On windows if you're going to use gradlew directly you need to run the windows variant of the command. See https://developer.android.com/studio/build/building-cmdline
So you should be running gradlew bundleRelease
From your screenshot you are running the *nix variant of ./gradlew bundleRelease. Note the removal of the leading ./ in the Windows version.

apk build file come with errors in react native android

Here, I have built the react native android app using this documentation Doc
in jenkins which was configured on ubuntu 16.04 (in virtual machine).
Here is the build command which I used to build the react native app(android) in Jenkins
cd $WORKSPACE && chmod -R 777 ./android && cd ./android && npm install && ./gradlew clean && ./gradlew assembleDebug
The build process end successfully creating an apk file in the following path
build_release_v1/ws/android/app/build/outputs/apk/
Note build_release_v1 is the jenkins project name and ws is for the workspace of it.
Though the apk is created it comes up with following errors
What may be the case ....please help me with this ...Thanks in advance...
The problem is that if you want a debug build (since you are using assembleDebug), React Native generates an APK that expects to have a connection to the bundle server (it does the same as react-native run-android). My guess is that you want to test the app without the bundler, so you have two options: either run assembleRelease instead (have a look here for more details) or manually create the bundled JavaScript code and then create the APK. Please refer to this question for details.

How to compile kivy and python files to apk

i want to convert my python and kivy files into signed and unsigned apk. i work on windows but for compiling using python for android in ubuntu in vm ware. After installing all necessary modules like kivy, python for android and android studio.
when i am compiling it's showing error that sdk not found.
is there any option for generating apk in windows or ubuntu or linux.
i also heard about buildozer and it also works on windows.
please suggest me something on it i'm new to kivy.
thanks
1
I suggest using buildozer instead of p4a - the buildozer uses it internally. It can also automatically download specified android sdk for you.
Install it using pip: sudo pip install buildozer
Once you have it installed, go to your project directory and type:
buildozer init
# edit the buildozer.spec, then
buildozer android_new debug deploy run
Find more info on the github.

How to create Android App with Cordova 3.4

Since yesterday, I have some problems with Cordova and Android. I can not create an functional Android App. iOS works.
In detail: I use a Mac (MacOS X 10.8.5) and have installed ADT 22.6.2 (with API 17/18/19) and added the sdk-tools to my PATH.
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/adt/sdk/tools:/Applications /adt/sdk/platform-tools:/usr/local/MacGPG2/bin
My configuration:
$ node -v
v0.10.26
$ cordova -v
3.4.1-0.1.0
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
My attempt to create an Cordova App:
$ cordova create XY com.wb.XY XY
Creating a new cordova project with name "XY" and id "com.wb.XY" at location "/.../XY"
$ cd XY
XY wb$ cordova platform add ios
Creating ios project...
XY wb$ cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.wb.XY
Name: XY
Android target: android-19
Copying template files...
Running: android update project --subprojects --path "platforms/android" --target android-19 --library "CordovaLib"
Resolved location of library project to: /.../XY/platforms/android/CordovaLib
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'XY'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/build.xml
Added file platforms/android/proguard-project.txt
Updated project.properties
Updated local.properties
No project name specified, using project folder name 'CordovaLib'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/CordovaLib/build.xml
Added file platforms/android/CordovaLib/proguard-project.txt
Project successfully created.
XY wb$ cordova platform list
Installed platforms: android 3.4.0, ios 3.4.1
Available platforms: amazon-fireos, blackberry10, firefoxos
XY wb$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
Fetching plugin "https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git" via git clone
Installing "org.apache.cordova.inappbrowser" for android
Installing "org.apache.cordova.inappbrowser" for ios
XY wb$
What is going wrong? There is no directory „gen“.
If I try to import the project into ADT/Eclipse, I got the message:
Errors occurred during the build.
Errors running builder 'Android Resource Manager' on project 'XY'.
Errors running builder 'Android Pre Compiler' on project 'XY'.
Path must include project and resource name: /XY
and
/XY/gen already exists but is not a source folder. Convert to a source folder or rename it.
Eclipse generates a folder called „gen“, but it is empty.
EDIT: Here is what I tried based on the input given in answers and comments:
I have installed Node.js and Cordova 3.4:
$ node -v
v0.10.26
$ cordova -v
3.4.1-0.1.0
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
I have done this as you described with CLI.
The Android SDK is in the system path:
$ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/adt/sdk/tools:/Applications/adt/sdk/platform-tools:/usr/local/MacGPG2/bin
Everything seems to be all right. Do you see any mistake? Do I need Apache Ant?
If I try to add android (without sudo), I have got the output shown in my question. Trying this as admin (with sudo), the result is the same.
With
$ cordova emulate android
I get:
...
BUILD SUCCESSFUL
Total time: 5 seconds
WARNING : no emulator specified, defaulting to Android_Tablet
Waiting for emulator...
2014-04-26 14:16:53.848 emulator64-arm[84081:f07] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
emulator64-arm: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
Booting up emulator (this may take a while)........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
It takes a very long time . . . after 15 minutes I broke off. The log at Eclipse shows always returning the same messages.
But with
$ cordova run android
I am able to install and launch the app on my Android-device. But if I try to import the project into Eclipse, the file XY.java is shown with many errors.
Do you have any idea what could be the problem?
I am still able to work with my existing apps (iOS and Android), but I can not create a new one for Android.
I am sharing with you the steps to create android PhoneGap app with cordova 3.4 version :-
1) Download and install Node.js.
2) Run this command on your terminal :-
$ sudo npm install -g cordova
3) Then create your project using following command :-
$ cordova create hello com.example.hello HelloWorld
4) Then before adding any platform , run the following command....Replace the path of android sdk with your system path :-
$ export PATH=${PATH}:/Users/taruna/Documents/adt-bundle-mac-x86_64-20131030/sdk/platform-tools:/Users/taruna/Documents/adt-bundle-mac-x86_64-20131030/sdk/tools
5) Now add your platform using following command :-
$ sudo cordova platform add android
6) Now you can successfully run your project on emulator using following command :-
$ cordova emulate android
And its done now.
`

Categories

Resources