-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
482 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Mon May 29 10:34:03 CST 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/github/foodiestudio/plugin/android/AndroidApplicationComposePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
package com.github.foodiestudio.plugin.android | ||
|
||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.github.foodiestudio.plugin.android.internal.configureAndroidCompose | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.apply | ||
import org.gradle.kotlin.dsl.getByType | ||
|
||
/** | ||
* 带 compose 的 android application plugin | ||
*/ | ||
class AndroidApplicationComposePlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply(AndroidApplicationPlugin::class) | ||
|
||
val extension = extensions.getByType<ApplicationExtension>() | ||
configureAndroidCompose(extension) | ||
} | ||
} | ||
} | ||
|
104 changes: 104 additions & 0 deletions
104
src/main/java/com/github/foodiestudio/plugin/android/AndroidApplicationPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.github.foodiestudio.plugin.android | ||
|
||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.android.build.api.dsl.CommonExtension | ||
import com.android.build.api.variant.ApplicationAndroidComponentsExtension | ||
import com.github.foodiestudio.plugin.android.internal.DefaultSdkVersions | ||
import com.github.foodiestudio.plugin.android.internal.configureGradleManagedDevices | ||
import com.github.foodiestudio.plugin.android.internal.configurePrintApksTask | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.JavaPluginExtension | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.provideDelegate | ||
import org.gradle.kotlin.dsl.withType | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
class AndroidApplicationPlugin : Plugin<Project> { | ||
|
||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
// 这里不需要指定 plugin 的版本 | ||
apply("com.android.application") | ||
apply("org.jetbrains.kotlin.android") | ||
} | ||
|
||
extensions.configure<ApplicationExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = DefaultSdkVersions.targetSdk | ||
configureGradleManagedDevices(this) | ||
} | ||
extensions.configure<ApplicationAndroidComponentsExtension> { | ||
configurePrintApksTask(this) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Configure base Kotlin with Android options | ||
*/ | ||
internal fun Project.configureKotlinAndroid( | ||
commonExtension: CommonExtension<*, *, *, *> | ||
) { | ||
commonExtension.apply { | ||
compileSdk = DefaultSdkVersions.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = DefaultSdkVersions.minSdk | ||
} | ||
|
||
compileOptions { | ||
// Up to Java 11 APIs are available through desugaring | ||
// https://developer.android.com/studio/write/java11-minimal-support-table | ||
sourceCompatibility = DefaultSdkVersions.java | ||
targetCompatibility = DefaultSdkVersions.java | ||
isCoreLibraryDesugaringEnabled = true | ||
} | ||
} | ||
|
||
configureKotlin() | ||
|
||
dependencies { | ||
add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:2.0.3") | ||
} | ||
} | ||
|
||
/** | ||
* Configure base Kotlin options for JVM (non-Android) | ||
*/ | ||
internal fun Project.configureKotlinJvm() { | ||
extensions.configure<JavaPluginExtension> { | ||
// Up to Java 11 APIs are available through desugaring | ||
// https://developer.android.com/studio/write/java11-minimal-support-table | ||
sourceCompatibility = DefaultSdkVersions.java | ||
targetCompatibility = DefaultSdkVersions.java | ||
} | ||
|
||
configureKotlin() | ||
} | ||
|
||
/** | ||
* Configure base Kotlin options | ||
*/ | ||
private fun Project.configureKotlin() { | ||
// Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947 | ||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
// Set JVM target to 11 | ||
jvmTarget = DefaultSdkVersions.java.toString() | ||
// Treat all Kotlin warnings as errors (disabled by default) | ||
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties | ||
val warningsAsErrors: String? by project | ||
allWarningsAsErrors = warningsAsErrors.toBoolean() | ||
freeCompilerArgs = freeCompilerArgs + listOf( | ||
"-opt-in=kotlin.RequiresOptIn", | ||
// Enable experimental coroutines APIs, including Flow | ||
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", | ||
"-opt-in=kotlinx.coroutines.FlowPreview", | ||
) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/github/foodiestudio/plugin/android/AndroidLibraryComposePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
package com.github.foodiestudio.plugin.android | ||
|
||
import com.android.build.api.dsl.LibraryExtension | ||
import com.github.foodiestudio.plugin.android.internal.configureAndroidCompose | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.apply | ||
import org.gradle.kotlin.dsl.getByType | ||
|
||
class AndroidLibraryComposePlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply(AndroidLibraryPlugin::class) | ||
|
||
val extension = extensions.getByType<LibraryExtension>() | ||
configureAndroidCompose(extension) | ||
extension.buildFeatures.buildConfig = false | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/foodiestudio/plugin/android/AndroidLibraryPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.foodiestudio.plugin.android | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import com.android.build.api.variant.LibraryAndroidComponentsExtension | ||
import com.android.build.gradle.LibraryExtension | ||
import com.github.foodiestudio.plugin.android.internal.DefaultSdkVersions | ||
import com.github.foodiestudio.plugin.android.internal.configureGradleManagedDevices | ||
import com.github.foodiestudio.plugin.android.internal.configurePrintApksTask | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.kotlin | ||
|
||
@Suppress("UnstableApiUsage") | ||
class AndroidLibraryPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.android.library") | ||
apply("org.jetbrains.kotlin.android") | ||
} | ||
|
||
extensions.configure<LibraryExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = DefaultSdkVersions.targetSdk | ||
buildFeatures.buildConfig = false | ||
configureGradleManagedDevices(this) | ||
} | ||
extensions.configure<LibraryAndroidComponentsExtension> { | ||
configurePrintApksTask(this) | ||
} | ||
dependencies { | ||
add("testImplementation", kotlin("test")) | ||
add("androidTestImplementation", kotlin("test")) | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/github/foodiestudio/plugin/android/internal/DefaultSdkVersions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.foodiestudio.plugin.android.internal | ||
|
||
import org.gradle.api.JavaVersion | ||
|
||
object DefaultSdkVersions { | ||
|
||
val java = JavaVersion.VERSION_11 | ||
|
||
const val minSdk: Int = 21 | ||
|
||
const val compileSdk: Int = 33 | ||
|
||
const val targetSdk: Int = 33 | ||
} |
Oops, something went wrong.