detox app could not be found, did you run './gradlew assembleAndroidTest'? - react-native

I am doing detox test for react native android version 0.57. I am getting this error.
Error is
Error: 'D:\folder\android\app\build\outputs\apk\androidTest\dev\debug\app-dev-debug-androidTest.apk' could not be found, did you run './gradlew assembleAndroidTest' ?
Package.json
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/dev/debug/app-dev-debug.apk",
"build": "cd android && .\\gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.attached",
"name": "192.168.83.101:5555"
}
Error picture

Detox has strange behavior where it mutates your path to your apk, if you specify it using binaryPath.
To specify the exact path to your apk, add an entry for testBinaryPath that points to the APK you want Detox to use.

This error is usually caused but not having built the test apk. It can usually be resolved by running
detox build -c android.emu.debug
If you make changes to your application you should always run the above script before running any test.
I usually run the following script to make sure that the build is uptodate before testing.
detox build -c android.emu.debug && detox test -c android.emu.debug

change path android/app/build/outputs/apk/dev/debug/app-dev-debug.apk to android/app/build/outputs/apk/debug/app-debug.apk
and detox automatically will create apk to path android/app/build/outputs/apk/AndroidTest/debug/app-debug-androidTest.apk

Related

React Native: Build apk file using Expo CLI

I'm a new learner on this platform.
I code a simple react native app using expo. But I want to build a .apk file.
I tried this command:
expo build:android
Then I sign up an expo account. After completing the building process it shows the download button. Just like the following picture: But its not apk file. It is .aab file.
So, I want to build an actual apk file.
How can I do that?
By default Expo, CLI builds the app into a .aab file format. this format is better for Google Play Store as it will be optimized for every device CPU architecture which results in a smaller app size.
In case you want to test for your device or emulator, run:
expo build:android -t apk
Update for new users:
Run the following:
› npm install -g eas-cli
› eas build -p android https://docs.expo.dev/build/setup/
expo build:android will be discontinued on January 4, 2023
to build a apk out of the file first you need to do some changes to your eas.json file.
By default, EAS Build produces Android App Bundle, you can change it by:
setting buildType to apk
setting developmentClient to true
setting gradleCommand to :app:assembleRelease, :app:assembleDebug or any othergradle command that produces APK
after changing the config you can run eas build -p android --profile preview to build the application
you can read more about this in docs
https://docs.expo.dev/build-reference/apk/
and here's a sample config i used for a basic project to build ( also you can find on docs )
{
"cli": {
"version": ">= 0.52.0"
},
"build": {
"preview": {
"android": {
"buildType": "apk"
}
},
"preview2": {
"android": {
"gradleCommand": ":app:assembleRelease"
}
},
"preview3": {
"developmentClient": true
},
"production": {}
}
}
--
also alternatively another possible way would be to get the bundle ( .aab ) file and convert it to apk using a too like bundletool. and you can find the apk ( universal.apk ) inside app.apks
bundletool build-apks --bundle=bundle.aab --output=app.apks --mode=universal
https://github.com/google/bundletool
From expo documentation :
When building for android you can choose to build APK (expo build:android -t apk) or Android App Bundle (expo build:android -t app-bundle).

Detox successfully builds but does not install app on Android emulator

I'm getting a successful detox build, and the emulator starts up, but the app is just never installed.
react-native run-android (without Detox) works fine.
The only error I'm seeing (including in verbose mode) is: "No instrumentation runner found", but I'm guessing that just means Detox can't find the app (which was never installed).
How can I get Detox to actually install the app onto the emulator? The only clue I see is that the package name has .test appended in this case which may be an issue, but I'm not at all sure of that.
(I tried to adb install the test app but that doesn't fix the issue, and also nothing shows up in the emulator when I run the command: adb -e install android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk. This installation command works fine for our standard debug apk.)
Log:
BUILD SUCCESSFUL in 25s
1029 actionable tasks: 1 executed, 1028 up-to-date
detox[66003] INFO: [test.js] configuration="android.emu.debug" reportSpecs=true readOnlyEmu=false useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1597412615185 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:ios:).)*$' --maxWorkers 1 e2e
detox[66004] INFO: [DetoxServer.js] server listening on localhost:55217...
detox[66004] ERROR: Error: No instrumentation runner found on device emulator-11448 for package com.myco.myapp.test
detox[66004] INFO: Example is assigned to undefined
detox[66004] INFO: Example: should have welcome screen
detox[66004] INFO: Example: should have welcome screen [SKIPPED]
detox[66003] ERROR: [cli.js] Error: Command failed: node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:ios:).)*$' --maxWorkers 1 e2e
detoxrc entry:
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.emulator",
"device": {
"avdName": "Pixel_API_28_AOSP"
}
},
This had to do with APK paths. Detox tries to compute a debug APK path, and if it's wrong it will come up with these errors. (If you build multiple versions of your APKs for different architectures, Detox doesn't appear to be able to handle that.)
The solution is to point to both of your APKs - the debug app ("binary"), and the instrumentation APK ("test binary"):
"binaryPath": "android/app/build/outputs/apk/debug/app-x86_64-debug.apk",
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",

Gradlew bundleRelease doesnt generate release apk in react-native

I try to get apk of app. I did it before well. However, I tried to use get apk of other app today but it doesnt give me release apk. why ?
I followed these steps : enter link description here
Normally, it takes 2-3 minutes but now it lasts just 3 sec and doesnt generate apk
it says this :
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 6.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
I had the same problem. Following command worked for me:
After the ./gradlew bundleRelease command we get a .aab version of our app. To get APK, you should run the app with release version on any device with the below command.
Make sure you have connected an android device
For the production ready app, firstly you have to remove the previous app from the device
Run this command in your-project/:
react-native run-android --variant=release
Then APK can be found in android/app/build/outputs/apk/release
Hope this helps
the short answer uses gradlew assembleRelease instead.
not short answer :) The command you are using gradlew bundleRelease builds an android App bundle. read this:
Difference between apk (.apk) and app bundle (.aab)
and this:
https://developer.android.com/guide/app-bundle
AAB file is new and not all stores support it.
Use gradlew bundleRelease to generate an app bundle (.aab file) and gradlew assembleRelease to generate an apk (.apk file). To install a release on your emulator, use react-native run-android --variant=release. I hope this helps
Cutting the long story short the command gradlew bundleRelease is used to generate an .aab file where as the command gradlew assembleRelease is used to generate .apk file so use the command accordingly
I made a file that called build.sh.
When i want to release a new version of android in ReactNative, just type and press sh ./build.sh in terminal.
My shell script in build.sh file:
npx jetify && cd android && ./gradlew clean && ./gradlew assembleRelease && ./gradlew bundleRelease && cd ..
You can simply open the Build Variants window on the bottom left hand corner of Android Studio and choose release as the current variant:
The following should solve your issue:
Open Android Studio and select "build bundle(s)" from Build/Build Bundle(s)/Apk(s)
Then, open your console and run
cd android && ./gradlew bundleRelease
from your project's root. You may encounter an error such as
Cannot add task 'wrapper' as a task with that name already exists., because overriding built-in tasks are deprecated in 4.8 and produces an error.
To prevent it, please update your android/build.gradle, as follows:
FROM:
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
TO:
wrapper {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
Lastly, don't forget to convert your .aab file to .apk through bundletool in order to test locally your app (exactly as an APK file)
step - 1) ./gradlew bundleRelease
step - 2) react-native run-android --variant=release
Make sure you have connected an android device
For the production-ready app, firstly you have to remove the previous app from the device
./gradlew app:bundleRelease Will fix your problem for sure.

What does " yarn build " command do? Are " npm build " and "yarn build" similar commands?

What does yarn build command do ?
Are yarn build and npm build the same? If not what's the difference?
yarn build and npm build are not existing commands by default. I think you mean yarn run build or npm run build.
build is a command which can be specified in your package.json file on the scripts property. See the example below.
{
"name": "mypackage",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.dev.js"
}
}
In this example, build is a shortcut for launching command webpack --config webpack.dev.js. You can use every keyword you want to define some shortcuts to launch commands.
And the only difference between the two commands it's the JS dependency manager you're using, yarn or npm.
More infos :
https://yarnpkg.com/lang/en/
https://www.npmjs.com/
"yarn build
Bundles the app into static files for production." from Create React App by MAD9135.
https://mad9135.github.io/F2020/modules/week3/02-react-tooling/07-create-react-app.html
yarn build is a shortcut of yarn run build
from original documentation:
Reference: https://classic.yarnpkg.com/lang/en/docs/cli/run/#toc-yarn-run-script
its the same i guess the real difference between yarn and npm is the performance and security that yarn provides.
yarn actually installing packages in parallelly and Npm only install one package at a time
And Yarn have more secure dependency.
Yarn is a package manager for your code. Yarn build makes a bundle of apps in one format and shows errors if the app has any problem that will make an error on the server.

React native - missing srcipt: ios

How to run react native app in iOS Stimulator?
I'm using npm run ios but I'm getting this error missing srcipt: ios
How to solve this?
You can run your project with just simple
react-native run-ios
And if you want to run on any particular simulator device run this
react-native run-ios --simulator="iPhone 6s" // Check your available devices
Usually we have package.json with any command line scripts, for example:
"scripts": {
"test": "node ./node_modules/jest/bin/jest.js --watchAll",
"dev": "exp start --dev --lan",
"build-android": "exp build:android",
"build-ios": "exp build:ios"
},
In your case, I am not sure from which source you initialized or cloned your project. But you will need to add and you can add without any issue the missing scripts.
You can label them by anything, e.g. "test" can be named by "mytest".
The example I have given above, you can see command exp, this is a module that you will need to install globally in order to run this command.
using npm install -g exp command. Then you can run the custom added scripts.
Find anything confusing, ask again.
Did you try running react-native run-ios?
https://facebook.github.io/react-native/docs/running-on-simulator-ios.html
If that doesn't work, you can always open project-directory/app/ios/[your-project-name].xcodeproj in xcode, and run the simulator in xcode directly.