Skip to content

Conversation

@enniel
Copy link
Contributor

@enniel enniel commented Sep 24, 2021

Summary

This patch remove unused .so files for reduce android .apk and .aab

Changelog

  • [Android] [Fixed] - Exclude unused .so files for reduce android .apk and .aab

Test Plan

I have created a repository for testing:
https://github.com/enniel/react-native-invalid-build-example

That lines includes patch for fix bug:
https://github.com/enniel/react-native-invalid-build-example/blob/f195ecdbeaca88ffb57c344615ede45ea0f6ef57/android/app/react.gradle#L331-L385

git clone https://github.com/enniel/react-native-invalid-build-example
cd react-native-invalid-build-example
npm i

debug, hermes disabled, without patch

git switch hermes-disabled-without-patch
npm run build:android:debug:apk

open android/app/build/outputs/apk/debug/app-debug.apk in android studio

debug-hermes-disabled-without-patch

debug, hermes enabled, without patch

git switch hermes-enabled-without-patch
npm run build:android:debug:apk

open android/app/build/outputs/apk/debug/app-debug.apk in android studio

debug-hermes-enabled-without-patch

debug, hermes disabled, with patch

git switch hermes-disabled-with-patch
npm run build:android:debug:apk

open android/app/build/outputs/apk/debug/app-debug.apk in android studio

debug-hermes-disabled-with-patch

debug, hermes enabled, with patch

git switch hermes-enabled-with-patch
npm run build:android:debug:apk

open android/app/build/outputs/apk/debug/app-debug.apk in android studio

debug-hermes-enabled-with-patch

release, hermes disabled, without patch

git switch hermes-disabled-without-patch
npm run build:android:release:apk

open android/app/build/outputs/apk/release/app-release.apk in android studio

release-hermes-disabled-without-patch

release, hermes enabled, without patch

git switch hermes-enabled-without-patch
npm run build:android:release:apk

open android/app/build/outputs/apk/release/app-release.apk in android studio

release-hermes-enabled-without-patch

release, hermes disabled, with patch

git switch hermes-disabled-with-patch
npm run build:android:release:apk

open android/app/build/outputs/apk/release/app-release.apk in android studio

release-hermes-disabled-with-patch

release, hermes enabled, with patch

git switch hermes-enabled-with-patch
npm run build:android:release:apk

open android/app/build/outputs/apk/release/app-release.apk in android studio

release-hermes-enabled-with-patch

@facebook-github-bot
Copy link
Contributor

Hi @enniel!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@analysis-bot
Copy link

analysis-bot commented Sep 24, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,706,017 -3,452
android hermes armeabi-v7a 7,236,134 -3,320
android hermes x86 8,126,071 -3,860
android hermes x86_64 8,091,037 -4,094
android jsc arm64-v8a 9,625,917 -3,061
android jsc armeabi-v7a 8,543,561 -2,930
android jsc x86 9,640,254 -3,470
android jsc x86_64 10,248,905 -3,715

Base commit: 18697ad

@analysis-bot
Copy link

analysis-bot commented Sep 24, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 18697ad

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2021
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 24, 2021
@facebook-github-bot
Copy link
Contributor

@ShikaSD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ecreeth
Copy link
Contributor

ecreeth commented Sep 24, 2021

Awesome! these are my results:

release, hermes disabled, without patch

release, hermes disabled, without patch

debug, hermes disabled, without patch

debug, hermes disabled, without patch

debug, hermes enabled, without patch

debug, hermes enabled, without patch

debug, hermes disabled, with patch

debug, hermes disabled, with patch

debug, hermes enabled, with patch

debug, hermes enabled, with patch

release, hermes enabled, without patch

release, hermes enabled, without patch

release, hermes disabled, with patch

release, hermes disabled, with patch

release, hermes enabled, with patch

release, hermes enabled, with patch

@cortinico
Copy link
Contributor

This is great stuff! Thanks for looking into it @enniel
Just one note: would you be able to re-apply the same logic also here:

private fun Project.cleanupVMFiles(enableHermes: Boolean, isRelease: Boolean, targetPath: String) {
// Delete the VM related libraries that this build doesn't need.
// The application can manage this manually by setting 'enableVmCleanup: false'
//
// This should really be done by packaging all Hermes related libs into
// two separate HermesDebug and HermesRelease AARs, but until then we'll
// kludge it by deleting the .so files out of the /transforms/ directory.
val libDir = "$buildDir/intermediates/transforms/"
fileTree(libDir) {
if (enableHermes) {
// For Hermes, delete all the libjsc* files
it.include("**/libjsc*.so")
if (isRelease) {
// Reduce size by deleting the debugger/inspector
it.include("**/libhermes-inspector.so")
it.include("**/libhermes-executor-debug.so")
} else {
// Release libs take precedence and must be removed
// to allow debugging
it.include("**/libhermes-executor-release.so")
}
} else {
// For JSC, delete all the libhermes* files
it.include("**/libhermes*.so")
}
}
.visit { visit ->
val targetVariant = ".*/transforms/[^/]*/$targetPath/.*".toRegex()
val path = visit.file.absolutePath.replace(File.separatorChar, '/')
if (path.matches(targetVariant) && visit.file.isFile) {
visit.file.delete()
}
}
}

@enniel
Copy link
Contributor Author

enniel commented Sep 26, 2021

This is great stuff! Thanks for looking into it @enniel
Just one note: would you be able to re-apply the same logic also here:

private fun Project.cleanupVMFiles(enableHermes: Boolean, isRelease: Boolean, targetPath: String) {
// Delete the VM related libraries that this build doesn't need.
// The application can manage this manually by setting 'enableVmCleanup: false'
//
// This should really be done by packaging all Hermes related libs into
// two separate HermesDebug and HermesRelease AARs, but until then we'll
// kludge it by deleting the .so files out of the /transforms/ directory.
val libDir = "$buildDir/intermediates/transforms/"
fileTree(libDir) {
if (enableHermes) {
// For Hermes, delete all the libjsc* files
it.include("**/libjsc*.so")
if (isRelease) {
// Reduce size by deleting the debugger/inspector
it.include("**/libhermes-inspector.so")
it.include("**/libhermes-executor-debug.so")
} else {
// Release libs take precedence and must be removed
// to allow debugging
it.include("**/libhermes-executor-release.so")
}
} else {
// For JSC, delete all the libhermes* files
it.include("**/libhermes*.so")
}
}
.visit { visit ->
val targetVariant = ".*/transforms/[^/]*/$targetPath/.*".toRegex()
val path = visit.file.absolutePath.replace(File.separatorChar, '/')
if (path.matches(targetVariant) && visit.file.isFile) {
visit.file.delete()
}
}
}

Done!

@facebook-github-bot
Copy link
Contributor

@ShikaSD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@cortinico
Copy link
Contributor

This is great stuff! Thanks for looking into it @enniel
Just one note: would you be able to re-apply the same logic also here:

private fun Project.cleanupVMFiles(enableHermes: Boolean, isRelease: Boolean, targetPath: String) {
// Delete the VM related libraries that this build doesn't need.
// The application can manage this manually by setting 'enableVmCleanup: false'
//
// This should really be done by packaging all Hermes related libs into
// two separate HermesDebug and HermesRelease AARs, but until then we'll
// kludge it by deleting the .so files out of the /transforms/ directory.
val libDir = "$buildDir/intermediates/transforms/"
fileTree(libDir) {
if (enableHermes) {
// For Hermes, delete all the libjsc* files
it.include("**/libjsc*.so")
if (isRelease) {
// Reduce size by deleting the debugger/inspector
it.include("**/libhermes-inspector.so")
it.include("**/libhermes-executor-debug.so")
} else {
// Release libs take precedence and must be removed
// to allow debugging
it.include("**/libhermes-executor-release.so")
}
} else {
// For JSC, delete all the libhermes* files
it.include("**/libhermes*.so")
}
}
.visit { visit ->
val targetVariant = ".*/transforms/[^/]*/$targetPath/.*".toRegex()
val path = visit.file.absolutePath.replace(File.separatorChar, '/')
if (path.matches(targetVariant) && visit.file.isFile) {
visit.file.delete()
}
}
}

Done!

Thanks for doing that 🙏

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @enniel in 6f12674.

When will my fix make it into a release? | Upcoming Releases

3 similar comments
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @enniel in 6f12674.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @enniel in 6f12674.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @enniel in 6f12674.

When will my fix make it into a release? | Upcoming Releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants