mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
chore: configure product flavors and split APKs to reduce APK size
This commit is contained in:
Generated
+1
@@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ANTLRGenerationPreferences">
|
||||
<option name="perGrammarGenerationSettings">
|
||||
|
||||
+70
-8
@@ -10,26 +10,87 @@ agree to abide the terms specified in the [CODE OF CONDUCT](./CODE_OF_CONDUCT.md
|
||||
|
||||
> NOTE:
|
||||
>
|
||||
> At the time of this writing, the stable version of Android Studio (Electric Eel) is bundled with JDK 11. Only Android Studio Flamingo and newer are bundled with JDK 17.
|
||||
> At the time of this writing, the stable version of Android Studio (Electric Eel) is bundled with
|
||||
> JDK 11. Only Android Studio Flamingo and newer are bundled with JDK 17.
|
||||
|
||||
## Build the project
|
||||
|
||||
Open the project in Android Studio. No extra steps are needed for this.
|
||||
|
||||
It is possible to build AndroidIDE in AndroidIDE itself. But, as it might be a too heavy task for an Android device to be able to build the project, Android Studio is always recommended.
|
||||
It is possible to build AndroidIDE in AndroidIDE itself. But, as it might be a too heavy task for an
|
||||
Android device to be able to build the project, Android Studio is always recommended.
|
||||
|
||||
## Project structure
|
||||
|
||||
The `:app` module has two product flavors based on CPU ABI :
|
||||
- `arm64-v8a`
|
||||
- `armeabi-v7a`
|
||||
|
||||
These flavors are used to build separate APKs with ABI-specific assets. The overall logic of the application remains the same across both flavors, but the assets differ based on the targeted CPU architecture.
|
||||
|
||||
The project structure is as follows :
|
||||
|
||||
```
|
||||
- app
|
||||
- src
|
||||
- arm64-v8a
|
||||
- assets
|
||||
- <arm64-v8a specific assets>
|
||||
- armeabi-v7a
|
||||
- assets
|
||||
- <armeabi-v7a specific assets>
|
||||
- main
|
||||
- assets
|
||||
- <shared assets>
|
||||
```
|
||||
|
||||
When modifying assets, please make sure to update the assets in the appropriate flavor-specific directories (app/src/arm64-v8a/assets or app/src/armeabi-v7a/assets).
|
||||
|
||||
## Split APKs, Size Reduction, and Optimization
|
||||
|
||||
By utilizing product flavors and split APKs based on CPU ABI, the size of the APKs have been optimized. Each APK now includes only the shared libraries and assets specific to a particular ABI, resulting in reduced file sizes for each APK.
|
||||
|
||||
It's important to note that there are some issues that arise when using product flavors and split APKs. Specifically, the generation of invalid APKs for certain flavors occurs due to the inclusion of incompatible assets.
|
||||
|
||||
For instance, let's consider the 'armeabi-v7a' flavor. Currently, two APKs are generated for this flavor:
|
||||
|
||||
```
|
||||
app-armeabi-v7a-armeabi-v7a-debug.apk
|
||||
app-armeabi-v7a-arm64-v8a-debug.apk
|
||||
```
|
||||
|
||||
However, the second APK listed above is invalid because it includes assets only for 'armeabi-v7a' and but contains 'arm64-v78a' shared libraries. As a result, installing this APK will render it non-functional.
|
||||
|
||||
Likewise, for the 'arm64-v8a' flavor, an APK named `app-arm64-v8a-armeabi-v7a-debug.apk` is generated. Although this APK may be functional due to the backwards compatibility of arm64-v8a with armeabi-v7a, proper functioning of the app cannot be guaranteed.
|
||||
|
||||
Considering these issues, it is recommended that only the following APKs be used:
|
||||
|
||||
```
|
||||
app-arm64-v8a-arm64-v8a-debug.apk
|
||||
app-armeabi-v7a-armeabi-v7a-debug.apk
|
||||
```
|
||||
|
||||
## Source code format
|
||||
|
||||
- Indents : 2-space
|
||||
- Java : `GoogleStyle`. Either use `google-java-format` or import [this](https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml) code style.
|
||||
- Kotlin: Use [`ktfmt`](https://plugins.jetbrains.com/plugin/14912-ktfmt) IntelliJ Plugin and set the code style to `Google (internal)`. [`Learn more`](https://github.com/facebook/ktfmt#intellij-android-studio-and-other-jetbrains-ides).
|
||||
- Java : `GoogleStyle`. Either use `google-java-format` or
|
||||
import [this](https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml)
|
||||
code style.
|
||||
- Kotlin: Use [`ktfmt`](https://plugins.jetbrains.com/plugin/14912-ktfmt) IntelliJ Plugin and set
|
||||
the code style to `Google (internal)`
|
||||
. [`Learn more`](https://github.com/facebook/ktfmt#intellij-android-studio-and-other-jetbrains-ides)
|
||||
.
|
||||
- XML : Default Android Studio formatter with 2-space indentations.
|
||||
|
||||
## Propose a change
|
||||
|
||||
Before proposing a change, it is always recommended to open an issue and discuss it with the maintainers.
|
||||
Before proposing a change, it is always recommended to open an issue and discuss it with the
|
||||
maintainers.
|
||||
|
||||
**The `main` branch is protected and requires all the commits to be signed with your GPG key and the commit history to be linear.** See [protected branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches).
|
||||
**The `main` branch is protected and requires all the commits to be signed with your GPG key and the
|
||||
commit history to be linear.**
|
||||
See [protected branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches)
|
||||
.
|
||||
|
||||
To contribute to this project,
|
||||
|
||||
@@ -42,10 +103,11 @@ To contribute to this project,
|
||||
## Issues & Pull requests
|
||||
|
||||
Use the issue/PR templates whenever possible. Provide a proper title and a clear description of the
|
||||
issue/PR. For bug reports, provide a step-by-step procedure to reproduce the issue. Always put things like crash
|
||||
issue/PR. For bug reports, provide a step-by-step procedure to reproduce the issue. Always put
|
||||
things like crash
|
||||
logs, and build outputs in `code blocks`.
|
||||
|
||||
|
||||
## Contact us
|
||||
|
||||
If you want to discuss anything about the project, you can discuss it in
|
||||
the [Telegram group](https://t.me/androidide_discussions).
|
||||
|
||||
+46
-12
@@ -1,6 +1,9 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import androidx.navigation.safe.args.generator.ext.capitalize
|
||||
import com.android.build.gradle.BaseExtension
|
||||
import java.util.Base64
|
||||
import java.util.Locale
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
@@ -11,6 +14,8 @@ plugins {
|
||||
id("androidx.navigation.safeargs.kotlin")
|
||||
}
|
||||
|
||||
val flavorsAbis = arrayOf("arm64-v8a", "armeabi-v7a")
|
||||
|
||||
android {
|
||||
namespace = BuildConfig.packageName
|
||||
|
||||
@@ -21,6 +26,29 @@ android {
|
||||
|
||||
compileOptions { isCoreLibraryDesugaringEnabled = true }
|
||||
|
||||
flavorDimensions.add("default")
|
||||
productFlavors {
|
||||
flavorsAbis.forEach(this::create)
|
||||
}
|
||||
|
||||
splits {
|
||||
abi {
|
||||
reset()
|
||||
|
||||
isEnable = true
|
||||
isUniversalApk = false
|
||||
|
||||
// TODO: Find a way to enable split APKs in product flavors. If this is possible, we can configure
|
||||
// each flavor to include only a single ABI. For example, for the 'arm64-v8a' flavor,
|
||||
// we can configure it to include only 'arm64-v8a' libraries. Size of APK can further be
|
||||
// reduced by 10-15MB once this is achieved.
|
||||
//
|
||||
// See the contribution guidelines for more information.
|
||||
@Suppress("ChromeOsAbiSupport")
|
||||
include(*flavorsAbis)
|
||||
}
|
||||
}
|
||||
|
||||
downloadSigningKey()
|
||||
|
||||
// Keystore credentials
|
||||
@@ -256,18 +284,24 @@ tasks.create("generateInitScript") {
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
val dependents =
|
||||
listOf(
|
||||
"mergeDebugAssets",
|
||||
"mergeReleaseAssets",
|
||||
"lintAnalyzeDebug",
|
||||
"lintAnalyzeRelease",
|
||||
"lintVitalAnalyzeRelease"
|
||||
)
|
||||
for (dependent in dependents) {
|
||||
tasks.getByName(dependent).apply {
|
||||
dependsOn(":subprojects:tooling-api-impl:copyJarToAssets")
|
||||
dependsOn("generateInitScript")
|
||||
extensions.getByType<BaseExtension>().apply {
|
||||
val flavorNames = productFlavors.map { it.name.capitalize(Locale.getDefault()) }
|
||||
val dependents =
|
||||
listOf(
|
||||
"merge@@DebugAssets",
|
||||
"merge@@ReleaseAssets",
|
||||
"lintAnalyze@@Debug",
|
||||
"lintAnalyze@@Release",
|
||||
"lintVitalAnalyze@@Release"
|
||||
)
|
||||
|
||||
for (dependent in dependents) {
|
||||
for (flavorName in flavorNames) {
|
||||
tasks.getByName(dependent.replace("@@", flavorName)).apply {
|
||||
dependsOn(":subprojects:tooling-api-impl:copyJarToAssets")
|
||||
dependsOn("generateInitScript")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user