-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * Basic ads (#39) * init * Reduced target SDK value for Logging. * Fixed Gradle misconfig * Changed Compose version to latest. * * Added Annotations for GoogleMobileAds dependencies and ExperimentalBasicAds * Created a transitive dependence on MobileAds * Updated Composables and compose dependency * Changed order of iOS logging * Basic-Ads is WORKING on iOS!!!! * Created AdLoader.kt and updated relevant dependencies * Fixed Gradle misconfig * Changed Compose version to latest. * * Added Annotations for GoogleMobileAds dependencies and ExperimentalBasicAds * Created a transitive dependence on MobileAds * Updated Composables and compose dependency * Changed order of iOS logging * Basic-Ads is WORKING on iOS!!!! * Created AdLoader.kt and updated relevant dependencies * init * Fixed InterstitialAd * Added RewardedInterstitialAds * Added RewardedAds * Added RewardedInterstitialAd and linked all to composables. * Added iosMain implementation of AdLoader * Finished iosMain Composables.kt. * Built and removed "super" since it is not possible in obj-c * Added super simple way to return AdUnitId. * Fixed a small error related to expect/actual * Updated Dokka documentation * Added CompileOnly for AdMob Dependency Removed all traces of Javascript implementation * Verified build using publishToMavenLocal * * Added Default AdUnitIds for each ad type * Fixed Dokka errors in Composables.kt * Updated README.MD * * Updated documentation for Basic-Ads * * Updated version to v0.2.0 * * Updated README.md * * Added AudioByte and AudioByteBuilder * * Updated README.md for AudioByte * * Cleaned up final TODOs * * Added Medium Basic Ads walkthrough * * Added Medium Basic Ads walkthrough * Update README.md
- Loading branch information
1 parent
533e1ca
commit 55d5d39
Showing
243 changed files
with
14,645 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Basic-Ads | ||
<img src="../docs/images/basic.png" alt="basic" height="240" align="right"/> | ||
|
||
[Basic-Ads](https://basic.lexilabs.app/basic-ads) [](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-ads) | ||
|
||
A Kotlin Multiplatform library to rapidly get Gooble AdMob running on Android and iOS | ||
|
||
 | ||
 | ||
|
||
### How it works | ||
Basic-Ads uses the existing Android and iOS Google AdMob libraries to display ads as `Composables`. | ||
A [full walkthrough](https://medium.com/@robert.jamison/composable-ads-f8795924aa0d) is available on my Medium Blog. | ||
|
||
## Preparation | ||
For **Android**, complete the steps in AdMob's instructions: | ||
|
||
* [Configure your app](https://developers.google.com/admob/android/quick-start#import_the_mobile_ads_sdk) | ||
|
||
For **iOS**, complete the steps in AdMob's instructions: | ||
|
||
* [Import the Mobile Ads SDK](https://developers.google.com/admob/ios/quick-start#import_the_mobile_ads_sdk) | ||
|
||
* [Update your Info.plist](https://developers.google.com/admob/ios/quick-start#update_your_infoplist) | ||
|
||
***NOTE: For Xcode 13+, you can update your [Custom iOS Target Properties](https://useyourloaf.com/blog/xcode-13-missing-info.plist/).*** | ||
|
||
## Installation | ||
Add your dependencies from Maven | ||
```toml | ||
# in your 'libs.versions.toml' file | ||
[versions] | ||
lexilabs-basic = "+" # gets the latest version | ||
google-play-services-ads = "+" # you did this during the preparation step | ||
|
||
[libraries] | ||
lexilabs-basic-images = { module = "app.lexilabs.basic:basic-ads", version.ref = "lexilabs-basic"} | ||
google-play-services-ads = { module = "com.google.android.gms:play-services-ads", version.ref = "google-play-services-ads"} | ||
``` | ||
|
||
then include the library in your gradle build | ||
```kotlin | ||
// in your 'composeApp/build.gradle.kts' file | ||
sourceSets { | ||
commonMain.dependencies { | ||
implementation(libs.lexilabs.basic.ads) | ||
implementation(libs.google.play.services.ads) | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
Call [BasicAds.initialize] in your `commonMain` before building ads. | ||
***NOTE: You do not need to initialize within each platform.*** | ||
|
||
```kotlin | ||
// in your 'composeApp/src/commonMain/App.kt' file | ||
@OptIn(DependsOnGoogleMobileAds::class) | ||
@Composable | ||
fun App() { | ||
// You'll need to access your platform-specific context (Android) or null (iOS) to pass as an `Any?` argument | ||
BasicAds.initialize( | ||
platformContext | ||
) | ||
//... | ||
} | ||
``` | ||
|
||
Now you can build ads: | ||
|
||
```kotlin | ||
// in your 'composeApp/src/commonMain/AdScreen.kt' file | ||
@Composable | ||
fun AdScreen() { | ||
BannerAd() // Results in a Test Banner Ad being created | ||
// You'll need to access your platform-specific Activity (Android) or null (iOS) to pass as an `Any?` argument | ||
InterstitialAd(activity) // Results in a Test Interstitial Ad being created | ||
RewardedInterstitialAd(activity) // Results in a Test Rewarded Interstitial Ad (Beta) being created | ||
RewardedAd(activity) // Results in a Test Rewarded Ad being created | ||
} | ||
``` | ||
|
||
If you want to customize your ad experience, you can take advantage of lambdas: | ||
```kotlin | ||
// in your 'composeApp/src/commonMain/AdScreen.kt' file | ||
@Composable | ||
fun AdScreen() { | ||
// You'll need to access your platform-specific Activity (Android) or null (iOS) to pass as an `Any?` argument | ||
RewardedAd( | ||
activity = activity, | ||
adUnitId = AdUnitId.autoSelect( | ||
"YOUR_ANDROID_AD_UNIT_ID", | ||
"YOUR_IOS_AD_UNIT_ID" | ||
), | ||
onDismissed = { | ||
doSomethingElse() | ||
}, | ||
onRewardEarned = { | ||
playSomeCoolSound() | ||
} | ||
) | ||
} | ||
``` | ||
|
||
In case you need it, here's some [additional documentation](https://basic.lexilabs.app/basic-ads) | ||
|
||
### \[Advanced Users Only\] How to deal with building this garbage | ||
1. Find a large cup. It must exist in the real world. | ||
2. Fill said cup to the brim with some sort of caffeinated beverage. | ||
3. Click `File` > `Invalidate Caches...`, check all boxes and hit `invalidate and restart` | ||
4. Click `Sync` for gradle if banner exists. Ignore the flood of warning lights and klaxons. | ||
5. Click `Build` > `Clean Cache`. Ignore the plethora of errors | ||
6.Once complete, click `Build` > `Rebuild Project`. NOTE: Despite religious preference, prayer is encouraged. |
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,102 @@ | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
|
||
plugins { | ||
alias(libs.plugins.multiplatform) | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlinx.binary.compatibility.validator) | ||
alias(libs.plugins.dokka) | ||
alias(libs.plugins.native.cocoapods) | ||
alias(libs.plugins.composeCompiler) | ||
`maven-publish` | ||
signing | ||
} | ||
|
||
kotlin { | ||
|
||
// FORCES CHECK OF PUBLIC API DECLARATIONS | ||
explicitApi() | ||
|
||
listOf( | ||
iosX64(), // mobile | ||
iosArm64(), // mobile | ||
iosSimulatorArm64(), // mobile | ||
).forEach { | ||
it.binaries.framework { | ||
baseName = "basic-ads" | ||
isStatic = true | ||
} | ||
} | ||
|
||
cocoapods { | ||
ios.deploymentTarget = libs.versions.ios.deploymentTarget.get() | ||
framework { | ||
baseName = "GoogleMobileAds" | ||
// Enable "isStatic", build, disable "isStatic", then build again. | ||
// isStatic = true | ||
} | ||
noPodspec() | ||
pod("Google-Mobile-Ads-SDK") { | ||
moduleName = "GoogleMobileAds" | ||
version = libs.versions.adMob.cocoapods.get() | ||
extraOpts += listOf("-compiler-option", "-fmodules") | ||
} | ||
} | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
implementation(libs.compose.foundation) | ||
implementation(libs.annotations) | ||
implementation(project(":basic-logging")) | ||
} | ||
androidMain.dependencies { | ||
implementation(libs.compose.ui) | ||
compileOnly(libs.google.play.services.ads) | ||
} | ||
iosMain.dependencies {} | ||
} | ||
|
||
//https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers | ||
targets.withType<KotlinNativeTarget> { | ||
compilations["main"].compileTaskProvider.configure{ | ||
compilerOptions { | ||
freeCompilerArgs.add("-Xexport-kdoc") | ||
} | ||
} | ||
} | ||
|
||
// https://youtrack.jetbrains.com/issue/KT-61573 | ||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
compilerOptions { | ||
freeCompilerArgs.add("-Xexpect-actual-classes") | ||
} | ||
|
||
// Android JVM target target options | ||
androidTarget { | ||
publishLibraryVariants("release", "debug") | ||
compilations.all{ | ||
compileTaskProvider.configure{ | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_17) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "app.lexilabs.basic.ads" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 24 | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
buildFeatures{ | ||
compose = true | ||
} | ||
} |
Oops, something went wrong.