Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
ADFA-2179 ndk template#882
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4c6a54d3733c2bce4f894d6415d35b12945File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package com.itsaky.androidide.templates.base | ||
| import com.itsaky.androidide.templates.ModuleTemplate | ||
| import com.itsaky.androidide.templates.RecipeExecutor | ||
| import com.itsaky.androidide.templates.base.util.AndroidManifestBuilder.ConfigurationType.APPLICATION_ATTR | ||
| import com.itsaky.androidide.templates.base.modules.android.ndkBuildGradleSrcKts | ||
| import com.itsaky.androidide.templates.base.modules.android.ndkBuildGradleSrcGroovy | ||
| import com.itsaky.androidide.templates.SrcSet | ||
| import com.itsaky.androidide.templates.base.util.SourceWriter | ||
| import java.io.File | ||
| class NdkModuleTemplateBuilder( | ||
| private val ndkVersion: String? = null, | ||
| private val abiFilters: List<String>? = null, | ||
| private val cppFlags: String? = null | ||
| ) : AndroidModuleTemplateBuilder() { | ||
| fun srcNativeFilePath(srcSet: SrcSet, fileName: String): File { | ||
| // place under src/main/cpp | ||
| val cppDir = File(javaSrc(srcSet), "../cpp") | ||
| if (!cppDir.exists()) { | ||
| cppDir.mkdirs() | ||
| } | ||
| return File(cppDir, fileName) | ||
| } | ||
| inline fun writeCpp( | ||
| writer: SourceWriter, | ||
| fileName: String, | ||
| crossinline cppSrcProvider: () -> String | ||
| ) { | ||
| val src = cppSrcProvider() | ||
| if (src.isNotBlank() && fileName.isNotBlank()) { | ||
| executor.save(src, srcNativeFilePath(SrcSet.Main, fileName)) | ||
| } | ||
| } | ||
| inline fun writeCMakeList( | ||
| writer: SourceWriter, | ||
| fileName: String, | ||
| crossinline cmakeSrcProvider: () -> String | ||
| ) { | ||
| val src = cmakeSrcProvider() | ||
| if (src.isNotBlank() && fileName.isNotBlank()) { | ||
| executor.save(src, srcNativeFilePath(SrcSet.Main, fileName)) | ||
| } | ||
| } | ||
jomen-adfa marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| override fun RecipeExecutor.buildGradle() { | ||
| val gradleContent = if (data.useKts) { | ||
| ndkBuildGradleSrcKts( | ||
| isComposeModule, | ||
| ndkVersion ?: "", | ||
| abiFilters ?: emptyList(), | ||
| cppFlags ?: "" | ||
| ) | ||
| } else { | ||
| ndkBuildGradleSrcGroovy( | ||
| isComposeModule, | ||
| ndkVersion ?: "", | ||
| abiFilters ?: emptyList(), | ||
| cppFlags ?: "" | ||
| ) | ||
| } | ||
| save(gradleContent, buildGradleFile()) | ||
| } | ||
jomen-adfa marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| inline fun ProjectTemplateBuilder.defaultAppModuleWithNdk( | ||
| name: String = ":app", | ||
| ndkVersion: String? = null, | ||
| abiFilters: List<String>? = null, | ||
| cppFlags: String? = null, | ||
| addAndroidX: Boolean = true, | ||
| copyDefAssets: Boolean = true, | ||
| crossinline block: NdkModuleTemplateBuilder.() -> Unit | ||
| ) { | ||
| val module = NdkModuleTemplateBuilder(ndkVersion, abiFilters, cppFlags).apply { | ||
| _name = name | ||
| templateName = 0 | ||
| thumb = 0 | ||
| preRecipe = commonPreRecipe { return@commonPreRecipe defModule } | ||
| postRecipe = commonPostRecipe { | ||
| if (copyDefAssets) { | ||
| copyDefaultRes() | ||
| manifest { | ||
| configure(APPLICATION_ATTR) { | ||
| androidAttribute("dataExtractionRules", "@xml/data_extraction_rules") | ||
| androidAttribute("fullBackupContent", "@xml/backup_rules") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (addAndroidX) baseAndroidXDependencies() | ||
| block() | ||
| }.build() as ModuleTemplate | ||
| modules.add(module) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.