Skip to content

Commit

Permalink
V0.2.0 (#40)
Browse files Browse the repository at this point in the history
* 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
robertjamison authored Nov 16, 2024
1 parent 533e1ca commit 55d5d39
Show file tree
Hide file tree
Showing 243 changed files with 14,645 additions and 106 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@

A Kotlin Multiplatform library to rapidly add basic features like pictures, logging, and audio to any project in a small and fast way.

| Platforms | Basic-Images | Basic-Logging | Basic-Sound |
|:--------------|:------------------:|:--------------------:|:------------------:|
| Android | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| iOS | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| macOS | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| watchOS | | :white_check_mark: | :white_check_mark: |
| tvOS | | :white_check_mark: | :white_check_mark: |
| nodeJS | | :white_check_mark: | :white_check_mark: |
| jsBrowser | | :white_check_mark: | :white_check_mark: |
| wasmJsBrowser | | :white_check_mark: | :white_check_mark: |
| JVM | :white_check_mark: | :white_check_mark: | |
| Linux | | :white_check_mark: | |
| Windows | | :white_check_mark: | |
| Platforms | Ads | Images | Logging | Sound |
|:--------------|:------------------:|:------------------------:|:------------------:|:------------------------:|
| Android | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| iOS | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| macOS | :no_entry_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| watchOS | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :white_check_mark: |
| tvOS | :no_entry_sign: | :hourglass_flowing_sand: | :white_check_mark: | :white_check_mark: |
| nodeJS | :no_entry_sign: | :hourglass_flowing_sand: | :white_check_mark: | :white_check_mark: |
| jsBrowser | :no_entry_sign: | :hourglass_flowing_sand: | :white_check_mark: | :white_check_mark: |
| wasmJsBrowser | :no_entry_sign: | :hourglass_flowing_sand: | :white_check_mark: | :white_check_mark: |
| JVM | :no_entry_sign: | :white_check_mark: | :white_check_mark: | :hourglass_flowing_sand: |
| Linux | :no_entry_sign: | :hourglass_flowing_sand: | :white_check_mark: | :hourglass_flowing_sand: |
| Windows | :no_entry_sign: | :hourglass_flowing_sand: | :white_check_mark: | :hourglass_flowing_sand: |

## Documentation
* [Basic-Images](basic-images/README.md) [![Maven Central](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-images?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-images)
* [Basic-Logging](basic-logging/README.md) [![Maven Central](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-logging?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-logging)
* [Basic-Sound](basic-sound/README.md) [![Maven Central](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-sound?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-sound)
* [Basic-Ads](basic-ads/README.md) [![MavenCentral](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-ads?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-ads)

## Quick Start
Add your dependencies from Maven
Expand All @@ -37,6 +38,7 @@ lexilabs-basic = "+" # gets the latest version
lexilabs-basic-images = { module = "app.lexilabs.basic:basic-images", version.ref = "lexilabs-basic" }
lexilabs-basic-logging = { module = "app.lexilabs.basic:basic-logging", version.ref = "lexilabs-basic" }
lexilabs-basic-sound = { module = "app.lexilabs.basic:basic-sound", version.ref = "lexilabs-basic" }
lexilabs-basic-ads = { module = "app.lexilabs.basic:basic-ads", version.ref = "lexilabs-basic" }
```
then include the library in your gradle build
```kotlin
Expand All @@ -46,6 +48,7 @@ sourceSets {
implementation(libs.lexilabs.basic.images)
implementation(libs.lexilabs.basic.logging)
implementation(libs.lexilabs.basic.sound)
implementation(libs.lexilabs.basic.ads)
}
}
```
113 changes: 113 additions & 0 deletions basic-ads/README.md
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) [![Maven Central](https://img.shields.io/maven-central/v/app.lexilabs.basic/basic-ads?color=blue)](https://central.sonatype.com/artifact/app.lexilabs.basic/basic-ads)

A Kotlin Multiplatform library to rapidly get Gooble AdMob running on Android and iOS

![badge-android](http://img.shields.io/badge/android-full_support-65c663.svg?style=flat)
![badge-ios](http://img.shields.io/badge/ios-full_support-65c663.svg?style=flat)

### 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.
102 changes: 102 additions & 0 deletions basic-ads/build.gradle.kts
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
}
}
Loading

0 comments on commit 55d5d39

Please sign in to comment.