Skip to content

Commit b3d94a4

Browse files
manny-jimenezManny Jimenez
andauthored
Adding Kotlin wrapper to java api (#3106)
* Adding Kotlin wrapper to java api * Fixing lint errors Co-authored-by: Manny Jimenez <[email protected]>
1 parent 2cba82f commit b3d94a4

File tree

8 files changed

+235
-3
lines changed

8 files changed

+235
-3
lines changed

firebase-app-distribution/firebase-app-distribution.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ dependencies {
4242
implementation project(path: ':firebase-components')
4343
implementation project(path: ':firebase-installations-interop')
4444
implementation project(path: ':firebase-common')
45-
implementation 'com.android.support:appcompat-v7:28.0.0'
4645
implementation project(path: ':firebase-installations')
4746

4847
testImplementation 'junit:junit:4.13.2'
@@ -56,8 +55,6 @@ dependencies {
5655

5756
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.5'
5857
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
59-
60-
implementation 'com.android.support:customtabs:28.0.0'
6158
implementation 'androidx.appcompat:appcompat:1.3.0'
6259
implementation "androidx.browser:browser:1.3.0"
6360
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
android.enableUnitTestBinaryResources=true
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
plugins {
16+
id 'firebase-library'
17+
id 'kotlin-android'
18+
}
19+
20+
firebaseLibrary {
21+
releaseWith project(':firebase-app-distribution')
22+
testLab.enabled = true
23+
publishJavadoc = true
24+
publishSources = true
25+
}
26+
27+
android {
28+
compileSdkVersion project.targetSdkVersion
29+
defaultConfig {
30+
minSdkVersion 16
31+
multiDexEnabled true
32+
targetSdkVersion project.targetSdkVersion
33+
versionName version
34+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
35+
}
36+
sourceSets {
37+
main.java.srcDirs += 'src/main/kotlin'
38+
test.java {
39+
srcDir 'src/test/kotlin'
40+
}
41+
androidTest.java.srcDirs += 'src/androidTest/kotlin'
42+
}
43+
testOptions.unitTests.includeAndroidResources = true
44+
}
45+
46+
dependencies {
47+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
48+
49+
implementation project(':firebase-common')
50+
implementation project(':firebase-components')
51+
implementation project(':firebase-common:ktx')
52+
implementation 'androidx.annotation:annotation:1.1.0'
53+
implementation project(path: ':firebase-app-distribution')
54+
55+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
56+
testImplementation 'junit:junit:4.12'
57+
testImplementation "com.google.truth:truth:$googleTruthVersion"
58+
testImplementation 'org.mockito:mockito-core:2.25.0'
59+
60+
androidTestImplementation 'junit:junit:4.12'
61+
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
62+
androidTestImplementation 'androidx.test:runner:1.2.0'
63+
androidTestImplementation 'androidx.test:core:1.2.0'
64+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.google.firebase.app.distribution.ktx">
3+
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
4+
<!--<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />-->
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
<application>
7+
<uses-library android:name="android.test.runner" />
8+
</application>
9+
10+
<instrumentation
11+
android:name="androidx.test.runner.AndroidJUnitRunner"
12+
android:targetPackage="3com.google.firebase.app.distribution.ktx" />
13+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.app.distribution.ktx
16+
17+
import androidx.test.core.app.ApplicationProvider
18+
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
19+
import com.google.common.truth.Truth
20+
import com.google.firebase.FirebaseApp
21+
import com.google.firebase.FirebaseOptions
22+
import com.google.firebase.appdistribution.FirebaseAppDistribution
23+
import com.google.firebase.ktx.Firebase
24+
import com.google.firebase.ktx.app
25+
import com.google.firebase.ktx.initialize
26+
import com.google.firebase.platforminfo.UserAgentPublisher
27+
import org.junit.After
28+
import org.junit.Before
29+
import org.junit.Test
30+
import org.junit.runner.RunWith
31+
32+
const val APP_ID = "APP_ID"
33+
const val API_KEY = "API_KEY"
34+
35+
const val EXISTING_APP = "existing"
36+
37+
@RunWith(AndroidJUnit4ClassRunner::class)
38+
abstract class BaseTestCase {
39+
@Before
40+
fun setUp() {
41+
Firebase.initialize(
42+
ApplicationProvider.getApplicationContext(),
43+
FirebaseOptions.Builder()
44+
.setApplicationId(APP_ID)
45+
.setApiKey(API_KEY)
46+
.setProjectId("123")
47+
.build()
48+
)
49+
50+
Firebase.initialize(
51+
ApplicationProvider.getApplicationContext(),
52+
FirebaseOptions.Builder()
53+
.setApplicationId(APP_ID)
54+
.setApiKey(API_KEY)
55+
.setProjectId("123")
56+
.build(),
57+
EXISTING_APP
58+
)
59+
}
60+
61+
@After
62+
fun cleanUp() {
63+
FirebaseApp.clearInstancesForTest()
64+
}
65+
}
66+
67+
@RunWith(AndroidJUnit4ClassRunner::class)
68+
class FirebaseAppDistributionTests : BaseTestCase() {
69+
@Test
70+
fun appDistribution_default_callsDefaultGetInstance() {
71+
Truth.assertThat(Firebase.appDistribution).isSameInstanceAs(FirebaseAppDistribution.getInstance())
72+
}
73+
74+
@Test
75+
fun appDistribution_withFirebaseApp_callsGetInstanceWithApp() {
76+
val app = Firebase.app(EXISTING_APP)
77+
Truth.assertThat(Firebase.appDistribution(app)).isSameInstanceAs(FirebaseAppDistribution.getInstance(app))
78+
}
79+
}
80+
81+
internal const val LIBRARY_NAME: String = "fire-app-distribution-ktx"
82+
83+
@RunWith(AndroidJUnit4ClassRunner::class)
84+
class LibraryVersionTest : BaseTestCase() {
85+
@Test
86+
fun libraryRegistrationAtRuntime() {
87+
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
88+
Truth.assertThat(publisher.userAgent).contains(LIBRARY_NAME)
89+
}
90+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- Copyright 2021 Google LLC -->
2+
<!-- -->
3+
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
4+
<!-- you may not use this file except in compliance with the License. -->
5+
<!-- You may obtain a copy of the License at -->
6+
<!-- -->
7+
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
8+
<!-- -->
9+
<!-- Unless required by applicable law or agreed to in writing, software -->
10+
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
11+
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
12+
<!-- See the License for the specific language governing permissions and -->
13+
<!-- limitations under the License. -->
14+
15+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
16+
package="com.google.firebase.app.distribution.ktx">
17+
<uses-sdk android:minSdkVersion="16"/>
18+
19+
<application>
20+
<service android:name="com.google.firebase.components.ComponentDiscoveryService" android:exported="false">
21+
<meta-data android:name="com.google.firebase.components:com.google.firebase.app.distribution.ktx.FirebaseAppDistributionKtxRegistrar"
22+
android:value="com.google.firebase.components.ComponentRegistrar" />
23+
</service>
24+
</application>
25+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.app.distribution.ktx
16+
17+
import androidx.annotation.Keep
18+
import com.google.firebase.BuildConfig
19+
import com.google.firebase.FirebaseApp
20+
import com.google.firebase.appdistribution.FirebaseAppDistribution
21+
import com.google.firebase.components.Component
22+
import com.google.firebase.components.ComponentRegistrar
23+
import com.google.firebase.ktx.Firebase
24+
import com.google.firebase.platforminfo.LibraryVersionComponent
25+
26+
/** Returns the [FirebaseAppDistribution] instance of the default [FirebaseApp]. */
27+
val Firebase.appDistribution: FirebaseAppDistribution
28+
get() = FirebaseAppDistribution.getInstance()
29+
30+
/** Returns the [FirebaseAppDistribution] instance of a given [FirebaseApp]. */
31+
fun Firebase.appDistribution(app: FirebaseApp): FirebaseAppDistribution =
32+
FirebaseAppDistribution.getInstance(app)
33+
34+
internal const val LIBRARY_NAME: String = "fire-app-distribution-ktx"
35+
36+
/** @suppress */
37+
@Keep
38+
class FirebaseAppDistributionKtxRegistrar : ComponentRegistrar {
39+
override fun getComponents(): List<Component<*>> =
40+
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
41+
}

subprojects.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ appcheck:firebase-appcheck:test-app
99
firebase-abt
1010
firebase-annotations
1111
firebase-app-distribution
12+
firebase-app-distribution:ktx
1213
firebase-common
1314
firebase-common:data-collection-tests
1415
firebase-common:ktx

0 commit comments

Comments
 (0)