diff --git a/gradle-plugin/src/main/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPlugin.kt b/gradle-plugin/src/main/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPlugin.kt index b6bab5eb8b..387738f4dc 100644 --- a/gradle-plugin/src/main/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPlugin.kt +++ b/gradle-plugin/src/main/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPlugin.kt @@ -55,6 +55,13 @@ class AndroidIDEInitScriptPlugin : Plugin { target.projectsLoaded { gradle -> gradle.rootProject.subprojects { sub -> + if (!sub.buildFile.exists()) { + // For subproject ':nested:module', + // ':nested' represented as a 'Project', but it may or may not have a buildscript file + // if the project doesn't have a buildscript, then the plugins should not be applied + return@subprojects + } + sub.buildscript.dependencies.apply { add("classpath", sub.ideDependency("gradle-plugin")) } diff --git a/gradle-plugin/src/test/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPluginTest.kt b/gradle-plugin/src/test/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPluginTest.kt index 9c48cb62bc..68e29ec55c 100644 --- a/gradle-plugin/src/test/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPluginTest.kt +++ b/gradle-plugin/src/test/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPluginTest.kt @@ -19,14 +19,8 @@ package com.itsaky.androidide.gradle import com.google.common.truth.Truth.assertThat import com.itsaky.androidide.buildinfo.BuildInfo -import com.itsaky.androidide.utils.FileProvider import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading import org.junit.jupiter.api.Test -import java.io.File -import java.io.FileNotFoundException -import kotlin.io.path.pathString /** * @author Akash Yadav @@ -60,7 +54,9 @@ class AndroidIDEInitScriptPluginTest { for ((project, variants) in mapOf(":app" to arrayOf("demoDebug", "fullDebug"))) { for (variant in variants) { assertThat(result.output).contains( - "Adding LogSender dependency (version '${depVersion(true)}') to variant '${variant}' of project '${project}'" + "Adding LogSender dependency (version '${ + depVersion(true) + }') to variant '${variant}' of project '${project}'" ) } } diff --git a/gradle-plugin/src/test/resources/sample-project/nested/app/.gitignore b/gradle-plugin/src/test/resources/sample-project/nested/app/.gitignore new file mode 100755 index 0000000000..58ef9a020f --- /dev/null +++ b/gradle-plugin/src/test/resources/sample-project/nested/app/.gitignore @@ -0,0 +1,2 @@ +/build +build.gradle.kts \ No newline at end of file diff --git a/gradle-plugin/src/test/resources/sample-project/nested/app/build.gradle.kts.in b/gradle-plugin/src/test/resources/sample-project/nested/app/build.gradle.kts.in new file mode 100755 index 0000000000..35857ece36 --- /dev/null +++ b/gradle-plugin/src/test/resources/sample-project/nested/app/build.gradle.kts.in @@ -0,0 +1,62 @@ + +plugins { + id("com.android.application") + @@PLUGINS@@ +} + +android { + namespace = "com.example.myapplication2" + compileSdk = 33 + buildToolsVersion = "33.0.2" + + defaultConfig { + applicationId = "com.example.myapplication2" + minSdk = 21 + targetSdk = 33 + versionCode = 1 + versionName = "1.0" + + vectorDrawables { + useSupportLibrary = true + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + buildTypes { + release { + isMinifyEnabled = true + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + + buildFeatures { + viewBinding = true + + } + + // LogSender must be applied to all the debuggable product flavors + flavorDimensions += "version" + productFlavors { + create("demo") { + dimension = "version" + applicationIdSuffix = ".demo" + versionNameSuffix = "-demo" + } + + create("full") { + dimension = "version" + applicationIdSuffix = ".full" + versionNameSuffix = "-full" + } + } +} + +dependencies { + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("com.google.android.material:material:1.9.0") +} diff --git a/gradle-plugin/src/test/resources/sample-project/nested/app/proguard-rules.pro b/gradle-plugin/src/test/resources/sample-project/nested/app/proguard-rules.pro new file mode 100755 index 0000000000..481bb43481 --- /dev/null +++ b/gradle-plugin/src/test/resources/sample-project/nested/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/gradle-plugin/src/test/resources/sample-project/nested/app/src/main/AndroidManifest.xml b/gradle-plugin/src/test/resources/sample-project/nested/app/src/main/AndroidManifest.xml new file mode 100755 index 0000000000..fe80d1d5a1 --- /dev/null +++ b/gradle-plugin/src/test/resources/sample-project/nested/app/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/gradle-plugin/src/test/resources/sample-project/nested/app/src/main/res/values/strings.xml b/gradle-plugin/src/test/resources/sample-project/nested/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..6fc03fbd36 --- /dev/null +++ b/gradle-plugin/src/test/resources/sample-project/nested/app/src/main/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + Sample app + \ No newline at end of file diff --git a/gradle-plugin/src/test/resources/sample-project/settings.gradle.kts b/gradle-plugin/src/test/resources/sample-project/settings.gradle.kts index eda7dada3b..e55a9bca5f 100755 --- a/gradle-plugin/src/test/resources/sample-project/settings.gradle.kts +++ b/gradle-plugin/src/test/resources/sample-project/settings.gradle.kts @@ -3,4 +3,5 @@ dependencyResolutionManagement { } rootProject.name = "Sample App" -include(":app") \ No newline at end of file +include(":app") +include(":nested:app") \ No newline at end of file