Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle not included in APK from within Android Studio #33018

Closed
djibarian opened this issue Feb 1, 2022 · 2 comments
Closed

Bundle not included in APK from within Android Studio #33018

djibarian opened this issue Feb 1, 2022 · 2 comments
Labels
Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@djibarian
Copy link

Description

Following on the issue #21132 I came to a slightly different problem. It seems that that issue refers to using react-native run-android, and that seems to finally work properly, i.e. the bundle is added to the APK properly.

But when building from Android Studio for release the bundle is still missing. I finally found the problem to be the same. build.gradle states that the default setting for jsBundleDirRelease is $buildDir/intermediates/assets/release, which is wrong. This must be changed to $buildDir/intermediates/assets/release/mergeReleaseAssets for Gradle to take the asset and add it to the APK.

So to avoid having to set jsBundleDirRelease to a proper value, it would be good to have the default value updated for this to work not only from the react-native run-android script, but also from Android Studio.

Version

0.66.4

Output of npx react-native info

System:
OS: macOS 12.2
CPU: (10) arm64 Apple M1 Pro
Memory: 195.25 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.0 - /usr/local/bin/node
Yarn: 1.22.15 - /usr/local/bin/yarn
npm: 8.3.0 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK:
API Levels: 26, 29, 30, 31, 32
Build Tools: 30.0.2, 30.0.3, 32.0.0
System Images: android-32 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8092744
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.2 => 17.0.2
react-native: ^0.66.4 => 0.66.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

Just try to build for release in Android Studio. Then inspect the APK in app/build/intermediates/apk and find that the assets folder is missing.

Snack, code example, screenshot, or link to a repository

No response

@react-native-bot react-native-bot added Platform: Android Android applications. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. labels Feb 1, 2022
@diego-paired
Copy link

Something similar happened to us when upgrading the Gradle plugin to v7 (from v4).
It's working again after downgrading to 4.2.2 (RN 0.67.1)

@cortinico
Copy link
Contributor

This must be changed to $buildDir/intermediates/assets/release/mergeReleaseAssets for Gradle to take the asset and add it to the APK.

The logic for bundling the asset is here:

react-native/react.gradle

Lines 317 to 329 in 10199b1

into ("assets/${targetPath}") {
from(jsBundleDir)
}
// Workaround for Android Gradle Plugin 3.2+ new asset directory
into ("merged_assets/${variant.name}/merge${targetName}Assets/out") {
from(jsBundleDir)
}
// Workaround for Android Gradle Plugin 3.4+ new asset directory
into ("merged_assets/${variant.name}/out") {
from(jsBundleDir)
}

I'm not sure what is the destination folder for AGP 7.x but if that is the case, we should be fine by just adding another rule there. Do you want to try submitting a PR for this @djibarian ?

@cortinico cortinico added Help Wanted :octocat: Issues ideal for external contributors. and removed Needs: Triage 🔍 labels Feb 1, 2022
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this issue Jan 15, 2023
…cebook#33057)

Summary:
Upgrade Android Gradle to 7.1.0 on template and fix a bug where the bundle was not getting included when building the app in release mode

Closes facebook#33002
Closes facebook#33018
Closes facebook#33046
Potentially fixes facebook#33029

## Changelog

[Android] [Changed] - Bump AGP to 7.1.0 and fix bundle inclusion in release mode

Pull Request resolved: facebook#33057

Test Plan:
1. Run `./scripts/test-manual-e2e.sh`
2. Select `A new RN app using the template` and `Android`
3. Test app on the emulator
4. Open Android studio build the app using release variant
4. Check the release apk using Android studio "Analyze APK" tool and ensure the bundle is included

![image](https://user-images.githubusercontent.com/11707729/152700410-3bcb80b0-35b6-4bdc-bf57-98a42a29e5a6.png)

Reviewed By: ShikaSD

Differential Revision: D34076884

Pulled By: cortinico

fbshipit-source-id: da4392af37e08e22dbcafba38476fd712141474a
@facebook facebook locked as resolved and limited conversation to collaborators Feb 21, 2023
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted :octocat: Issues ideal for external contributors. Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants