-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from gradle/tt/support-data-binding-in-android
Add viewBinding and dataBinding support for Android Applications
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
...id/src/integTest/groovy/org/gradle/api/experimental/android/AndroidApplicationSpec.groovy
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,98 @@ | ||
package org.gradle.api.experimental.android | ||
|
||
import org.gradle.test.fixtures.AbstractSpecification | ||
|
||
class AndroidApplicationSpec extends AbstractSpecification { | ||
def 'can create an android application using viewBinding that generates an activity binding class'() { | ||
given: | ||
buildFile << """ | ||
androidApplication { | ||
jdkVersion = 17 | ||
compileSdk = 34 | ||
namespace = "org.example.android.application" | ||
viewBinding { | ||
enabled = true | ||
} | ||
dependencies { | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
implementation("com.google.android.material:material:1.10.0") | ||
} | ||
} | ||
""" | ||
|
||
file("src/main/res/layout/activity_main.xml").text = """<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
tools:context=".MainActivity"> | ||
</androidx.coordinatorlayout.widget.CoordinatorLayout> | ||
""" | ||
|
||
file("src/main/java/org/example/android/application/MainActivity.java").text = """ | ||
package org.example.android.application; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import org.example.android.application.databinding.ActivityMainBinding; | ||
class MainActivity extends AppCompatActivity { | ||
private ActivityMainBinding binding; | ||
} | ||
""" | ||
|
||
file("src/main/AndroidManifest.xml").text = """<?xml version="1.0" encoding="utf-8"?> | ||
<manifest/> | ||
""" | ||
|
||
file("gradle.properties").text = """ | ||
android.useAndroidX=true | ||
""" | ||
|
||
expect: | ||
succeeds(":build") | ||
} | ||
|
||
def 'can create an android application using dataBinding'() { | ||
given: | ||
buildFile << """ | ||
androidApplication { | ||
jdkVersion = 17 | ||
compileSdk = 34 | ||
namespace = "org.example.android.application" | ||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
""" | ||
|
||
file("src/main/AndroidManifest.xml").text = """<?xml version="1.0" encoding="utf-8"?> | ||
<manifest/> | ||
""" | ||
|
||
expect: | ||
succeeds(":build") | ||
} | ||
|
||
def setup() { | ||
settingsFile << """ | ||
plugins { | ||
id("org.gradle.experimental.android-ecosystem") | ||
} | ||
dependencyResolutionManagement { | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
rootProject.name = "example" | ||
""" | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...gin-android/src/main/java/org/gradle/api/experimental/android/extensions/DataBinding.java
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,10 @@ | ||
package org.gradle.api.experimental.android.extensions; | ||
|
||
import org.gradle.api.provider.Property; | ||
import org.gradle.declarative.dsl.model.annotations.Restricted; | ||
|
||
@Restricted | ||
public interface DataBinding { | ||
@Restricted | ||
Property<Boolean> getEnabled(); | ||
} |
10 changes: 10 additions & 0 deletions
10
...gin-android/src/main/java/org/gradle/api/experimental/android/extensions/ViewBinding.java
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,10 @@ | ||
package org.gradle.api.experimental.android.extensions; | ||
|
||
import org.gradle.api.provider.Property; | ||
import org.gradle.declarative.dsl.model.annotations.Restricted; | ||
|
||
@Restricted | ||
public interface ViewBinding { | ||
@Restricted | ||
Property<Boolean> getEnabled(); | ||
} |