Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ android {
release {
manifestPlaceholders["sentryDsn"] = glitchtipDsn
}
create("profileable") {
initWith(getByName("release"))
isProfileable = true
matchingFallbacks += "release"
manifestPlaceholders["sentryDsn"] = glitchtipDsn
signingConfig = signingConfigs.getByName("debug")
}
}

testOptions {
Expand Down Expand Up @@ -118,6 +125,9 @@ android {
getByName("androidTest") {
manifest.srcFile("src/androidTest/AndroidManifest.xml")
}
getByName("profileable") {
java.srcDir("src/release/java")
}
}

lint {
Expand Down
109 changes: 59 additions & 50 deletions app/src/main/java/com/itsaky/androidide/assets/AssetsInstaller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,68 @@ import java.nio.file.Path
* Helper class to install assets for the IDE.
*/
sealed interface AssetsInstaller {
companion object {
/**
* Whether to use bundled assets installer or not. If `true`, bundled assets installer will
* be used.
*
* This is `true` for non-debug builds and for `instrumentation` builds. When updating this
* value, please update the corresponding value in `AndroidModuleConf.kt`.
*/
@Suppress("SimplifyBooleanWithConstants", "KotlinConstantConditions")
private val USE_BUNDLED_ASSETS =
when (BuildConfig.BUILD_TYPE) {
"instrumentation" -> true
"profileable" -> false
else -> !BuildConfig.DEBUG
}
Comment thread
itsaky-adfa marked this conversation as resolved.
Resolved

companion object {
/**
* The current assets installer.
*/
internal val CURRENT_INSTALLER = if (USE_BUNDLED_ASSETS) BundledAssetsInstaller else SplitAssetsInstaller
}

/**
* Whether to use bundled assets installer or not. If `true`, bundled assets installer will
* be used.
*
* This is `true` for non-debug builds and for `instrumentation` builds. When updating this
* value, please update the corresponding value in `AndroidModuleConf.kt`.
*/
@Suppress("SimplifyBooleanWithConstants", "KotlinConstantConditions")
private val USE_BUNDLED_ASSETS = !BuildConfig.DEBUG || BuildConfig.BUILD_TYPE == "instrumentation"
/**
* Called before installing assets.
*
* @param context The application context.
* @param stagingDir The staging directory for the assets.
*/
suspend fun preInstall(
context: Context,
stagingDir: Path,
)

/**
* The current assets installer.
*/
internal val CURRENT_INSTALLER = if (USE_BUNDLED_ASSETS) BundledAssetsInstaller else SplitAssetsInstaller
}
/**
* Called to install assets.
*
* @param context The application context.
* @param stagingDir The staging directory for the assets.
* @param cpuArch The CPU architecture of the device.
* @param entryName The name of the entry to install.
*/
@WorkerThread
suspend fun doInstall(
context: Context,
stagingDir: Path,
cpuArch: CpuArch,
entryName: String,
)

/**
* Called before installing assets.
*
* @param context The application context.
* @param stagingDir The staging directory for the assets.
*/
suspend fun preInstall(context: Context, stagingDir: Path)
/**
* Called after installing assets.
*/
suspend fun postInstall(
context: Context,
stagingDir: Path,
)

/**
* Called to install assets.
*
* @param context The application context.
* @param stagingDir The staging directory for the assets.
* @param cpuArch The CPU architecture of the device.
* @param entryName The name of the entry to install.
*/
@WorkerThread
suspend fun doInstall(
context: Context,
stagingDir: Path,
cpuArch: CpuArch,
entryName: String,
)

/**
* Called after installing assets.
*/
suspend fun postInstall(context: Context, stagingDir: Path)

/**
* Returns the expected size (in bytes) of the given entry.
*
* @param entryName The name of the entry whose size is requested.
* @return The expected size in bytes, or 0 if unknown.
*/
fun expectedSize(entryName: String): Long
/**
* Returns the expected size (in bytes) of the given entry.
*
* @param entryName The name of the entry whose size is requested.
* @return The expected size in bytes, or 0 if unknown.
*/
fun expectedSize(entryName: String): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ private val disableCoreLibDesugaringForModules =
* The name of the build type used for automated testing.
*/
private const val INSTRUMENTATION_BUILD_TYPE = "instrumentation"
private const val PROFILEABLE_BUILD_TYPE = "profileable"

/**
* Whether the given variant has bundled assets or not.
*
* This is `true` for non-debug builds and for [INSTRUMENTATION_BUILD_TYPE] builds. When updating this
* value, please update the corresponding value in `AssetsInstaller.kt` in `:app` module.
*/
internal fun hasBundledAssets(variant: Variant): Boolean = !variant.debuggable || variant.buildType == INSTRUMENTATION_BUILD_TYPE
internal fun hasBundledAssets(variant: Variant): Boolean =
when (variant.buildType) {
INSTRUMENTATION_BUILD_TYPE -> true
PROFILEABLE_BUILD_TYPE -> false
else -> !variant.debuggable
}

fun Project.configureAndroidModule(coreLibDesugDep: Provider<MinimalExternalModuleDependency>) {
var isAppModule = plugins.hasPlugin("com.android.application")
Expand Down
Loading