Skip to content

Commit 72be674

Browse files
authored
Merge pull request #214 from YAPP-Github/feature/#210-add-admob-banner
[FEAT] ์• ๋“œ๋ชน ๋ฐฐ๋„ˆ๋ฅผ ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.
2 parents 089547f + 66757a8 commit 72be674

File tree

14 files changed

+139
-52
lines changed

14 files changed

+139
-52
lines changed

โ€Ž.github/workflows/android_cd.ymlโ€Ž

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,17 @@ jobs:
5656
env:
5757
BASE_URL: ${{ secrets.BASE_URL }}
5858
AMPLITUDE_API_KEY: ${{ secrets.AMPLITUDE_API_KEY }}
59+
ADMOB_APP_ID_DEBUG: ${{ secrets.ADMOB_APP_ID_DEBUG }}
60+
ADMOB_APP_ID_RELEASE: ${{ secrets.ADMOB_APP_ID_RELEASE }}
61+
ADMOB_AD_UNIT_ID_DEBUG: ${{ secrets.ADMOB_AD_UNIT_ID_DEBUG }}
62+
ADMOB_AD_UNIT_ID_RELEASE: ${{ secrets.ADMOB_AD_UNIT_ID_RELEASE }}
5963
run: |
60-
echo -e "baseUrl=$BASE_URL\namplitudeApiKey=$AMPLITUDE_API_KEY" >> local.properties
64+
echo -e "baseUrl=$BASE_URL" > local.properties
65+
echo -e "amplitudeApiKey=$AMPLITUDE_API_KEY" >> local.properties
66+
echo -e "admobAppIdDebug=$ADMOB_APP_ID_DEBUG" >> local.properties
67+
echo -e "admobAppIdRelease=$ADMOB_APP_ID_RELEASE" >> local.properties
68+
echo -e "admobAdUnitIdDebug=$ADMOB_AD_UNIT_ID_DEBUG" >> local.properties
69+
echo -e "admobAdUnitIdRelease=$ADMOB_AD_UNIT_ID_RELEASE" >> local.properties
6170
6271
# 7. Debug Local Properties Check
6372
- name: Debug Local Properties

โ€Ž.github/workflows/android_ci.ymlโ€Ž

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@ jobs:
5757
env:
5858
BASE_URL: ${{ secrets.BASE_URL }}
5959
AMPLITUDE_API_KEY: ${{ secrets.AMPLITUDE_API_KEY }}
60+
ADMOB_APP_ID_DEBUG: ${{ secrets.ADMOB_APP_ID_DEBUG }}
61+
ADMOB_APP_ID_RELEASE: ${{ secrets.ADMOB_APP_ID_RELEASE }}
62+
ADMOB_AD_UNIT_ID_DEBUG: ${{ secrets.ADMOB_AD_UNIT_ID_DEBUG }}
63+
ADMOB_AD_UNIT_ID_RELEASE: ${{ secrets.ADMOB_AD_UNIT_ID_RELEASE }}
6064
run: |
61-
echo -e "baseUrl=$BASE_URL\namplitudeApiKey=$AMPLITUDE_API_KEY" >> local.properties
65+
echo -e "baseUrl=$BASE_URL" > local.properties
66+
echo -e "amplitudeApiKey=$AMPLITUDE_API_KEY" >> local.properties
67+
echo -e "admobAppIdDebug=$ADMOB_APP_ID_DEBUG" >> local.properties
68+
echo -e "admobAppIdRelease=$ADMOB_APP_ID_RELEASE" >> local.properties
69+
echo -e "admobAdUnitIdDebug=$ADMOB_AD_UNIT_ID_DEBUG" >> local.properties
70+
echo -e "admobAdUnitIdRelease=$ADMOB_AD_UNIT_ID_RELEASE" >> local.properties
6271
6372
# Debug Local Properties Check
6473
- name: Debug Local Properties

โ€Žapp/build.gradle.ktsโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ dependencies {
4141
implementation(projects.feature.navigator)
4242
implementation(libs.firebase.analytics)
4343
implementation(libs.firebase.crashlytics)
44+
implementation(libs.play.services.ads)
4445
}

โ€Žapp/src/main/AndroidManifest.xmlโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
android:usesCleartextTraffic="true"
2626
tools:targetApi="31">
2727

28+
<meta-data
29+
android:name="com.google.android.gms.ads.APPLICATION_ID"
30+
android:value="@string/admob_app_id" />
31+
2832
<activity
2933
android:name="com.yapp.navigator.MainActivity"
3034
android:windowSoftInputMode="adjustResize"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.yapp.orbit
22

33
import android.app.Application
4+
import com.google.android.gms.ads.MobileAds
45
import dagger.hilt.android.HiltAndroidApp
56

67
@HiltAndroidApp
78
class OrbitApplication : Application() {
89
override fun onCreate() {
910
super.onCreate()
11+
MobileAds.initialize(this)
1012
}
1113
}

โ€Žbuild-logic/src/main/java/com/yapp/convention/Extension.ktโ€Ž

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ internal fun CommonExtension<*, *, *, *, *, *>.addBuildConfigFields(project: Pro
4343
}
4444
}
4545

46+
internal fun CommonExtension<*, *, *, *, *, *>.addResValues(project: Project) {
47+
val admobAppIdDebug = project.getLocalProperty("admobAppIdDebug", "")
48+
val admobAppIdRelease = project.getLocalProperty("admobAppIdRelease", "")
49+
val admobAdUnitIdDebug = project.getLocalProperty("admobAdUnitIdDebug", "")
50+
val admobAdUnitIdRelease = project.getLocalProperty("admobAdUnitIdRelease", "")
51+
52+
buildTypes {
53+
getByName("debug") {
54+
resValue("string", "admob_app_id", admobAppIdDebug)
55+
resValue("string", "admob_ad_unit_id", admobAdUnitIdDebug)
56+
}
57+
getByName("release") {
58+
resValue("string", "admob_app_id", admobAppIdRelease)
59+
resValue("string", "admob_ad_unit_id", admobAdUnitIdRelease)
60+
}
61+
}
62+
}
63+
4664
internal fun Project.getLocalProperty(key: String, defaultValue: String? = null): String {
4765
val propertiesFile = rootProject.file("local.properties")
4866
if (propertiesFile.exists()) {

โ€Žbuild-logic/src/main/java/com/yapp/convention/KotlinAndroid.ktโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ internal fun Project.configureKotlinAndroid() {
4141
}
4242

4343
addBuildConfigFields(project)
44+
addResValues(project)
4445
}
4546

4647
configureKotlin()

โ€Žcore/ui/build.gradle.ktsโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ dependencies {
1717
implementation(libs.orbit.compose)
1818
implementation(libs.orbit.viewmodel)
1919
implementation(libs.lottie.compose)
20+
implementation(libs.play.services.ads)
2021
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3-
2+
<manifest>
43
</manifest>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.yapp.ui.component.banner
2+
3+
import android.annotation.SuppressLint
4+
import androidx.compose.foundation.layout.fillMaxWidth
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.Modifier
7+
import androidx.compose.ui.res.stringResource
8+
import androidx.compose.ui.viewinterop.AndroidView
9+
import com.google.android.gms.ads.AdRequest
10+
import com.google.android.gms.ads.AdSize
11+
import com.google.android.gms.ads.AdView
12+
import core.ui.R
13+
14+
@SuppressLint("MissingPermission")
15+
@Composable
16+
fun AdsBanner(
17+
modifier: Modifier = Modifier,
18+
) {
19+
val adUnitId = stringResource(id = R.string.admob_ad_unit_id)
20+
21+
AndroidView(
22+
modifier = modifier.fillMaxWidth(),
23+
factory = { context ->
24+
AdView(context).apply {
25+
setAdSize(AdSize.BANNER)
26+
this.adUnitId = adUnitId
27+
loadAd(AdRequest.Builder().build())
28+
}
29+
},
30+
update = { adView ->
31+
adView.loadAd(AdRequest.Builder().build())
32+
},
33+
)
34+
}

0 commit comments

Comments
ย (0)