Skip to content

Commit

Permalink
feat: add a workflow to generate release APK using input keys and zon…
Browse files Browse the repository at this point in the history
…es (#31)
  • Loading branch information
MortezaNedaei authored May 5, 2024
1 parent 43552be commit b2aea8a
Show file tree
Hide file tree
Showing 23 changed files with 362 additions and 12 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/release-dynamic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Android Dynamic Release
on:
workflow_dispatch:
inputs:
tapsellAppKey:
description: 'Tapsell App Key'
required: true
default: '76798342-99a7-4a5f-bf5a-60a088d5dcfb'
AdmobAppKey:
description: 'Admob App Key'
required: true
default: 'ca-app-pub-3940256099942544~3347511713'
ApplovinAppKey:
description: 'Applovin App Key'
required: true
default: '5WfZLCGTQmDr6Mf7BBEf5blVwrf8VBMJSmwUSq9-1q5bPpCH_OGAWEP2z2lRkmonLgPzG6gbL4DlvUF9frFmt6'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Decode Keystore
env:
# Create `SIGNING_KEY_STORE_BASE64` environment in GitHub secrets and place the base64 encoded value
# of your keystore there.
ENCODED_STRING: ${{ secrets.SIGNING_KEY_STORE_BASE64 }}
SIGNING_KEY_STORE_PATH: ${{ secrets.MYAPP_RELEASE_STORE_FILE }}

run: |
echo "keystore path: $MYAPP_RELEASE_STORE_FILE"
echo $ENCODED_STRING > keystore-b64.txt
base64 -d keystore-b64.txt > release.keystore
- name: Build Release apk
env:
SIGNING_KEY_STORE_PATH: ${{ secrets.MYAPP_RELEASE_STORE_FILE }}
SIGNING_KEY_ALIAS: ${{ secrets.MYAPP_RELEASE_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.MYAPP_RELEASE_KEY_PASSWORD }}
SIGNING_STORE_PASSWORD: ${{ secrets.MYAPP_RELEASE_STORE_PASSWORD }}
run: |
sh ./scripts/change-app.sh "${{ github.event.inputs.tapsellAppKey }}" "${{ github.event.inputs.AdmobAppKey }}" "${{ github.event.inputs.ApplovinAppKey }}"
./gradlew sample-kotlin:assembleRelease
- name: Upload Release Build to Artifacts
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: sample-kotlin/build/outputs/apk/release/*universal-release*.apk

14 changes: 14 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,18 @@ plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.kotlinJvm) apply false
}

ext {
set("TAPSELL_APP_ID", TapsellManifestPlaceholders.TAPSELL_APP_ID)
set("TAPSELL_APP_MARKET", TapsellManifestPlaceholders.TAPSELL_MARKET)
set("ADMOB_APP_ID", TapsellManifestPlaceholders.ADMOB_APP_ID)
set("APPLOVIN_APP_ID", TapsellManifestPlaceholders.APPLOVIN_APP_ID)
}

object TapsellManifestPlaceholders {
const val TAPSELL_APP_ID = "76798342-99a7-4a5f-bf5a-60a088d5dcfb"
const val TAPSELL_MARKET = "CafeBazaar"
const val ADMOB_APP_ID = "ca-app-pub-3940256099942544~3347511713"
const val APPLOVIN_APP_ID = "5WfZLCGTQmDr6Mf7BBEf5blVwrf8VBMJSmwUSq9-1q5bPpCH_OGAWEP2z2lRkmonLgPzG6gbL4DlvUF9frFmt6"
}
10 changes: 5 additions & 5 deletions sample-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ android {

addManifestPlaceholders(
mapOf(
"TapsellMediationAppMarket" to "CafeBazaar",
"TapsellMediationAppKey" to "76798342-99a7-4a5f-bf5a-60a088d5dcfb",
"TapsellMediationAdmobAdapterSignature" to "ca-app-pub-3940256099942544~3347511713",
"TapsellMediationApplovinAdapterSignature" to
"5WfZLCGTQmDr6Mf7BBEf5blVwrf8VBMJSmwUSq9-1q5bPpCH_OGAWEP2z2lRkmonLgPzG6gbL4DlvUF9frFmt6",
"TapsellMediationAppMarket" to properties["TAPSELL_APP_MARKET"] as String,
"TapsellMediationAppKey" to properties["TAPSELL_APP_ID"] as String,
"TapsellMediationAdmobAdapterSignature" to properties["ADMOB_APP_ID"] as String,
"TapsellMediationApplovinAdapterSignature" to properties["APPLOVIN_APP_ID"] as String,
)
)
}
Expand Down Expand Up @@ -106,3 +105,4 @@ dependencies {
androidTestImplementation(libs.espresso.core)
debugImplementation(libs.leakcanary)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ir.tapsell.sample.appopen

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import ir.tapsell.sample.databinding.FragmentInterstitialBinding
import ir.tapsell.shared.AdmobKeys
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class AppOpenFragment : Fragment() {

private var _binding: FragmentInterstitialBinding? = null
private val binding get() = _binding!!
private val viewModel by viewModels<AppOpenViewModel>()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentInterstitialBinding.inflate(inflater, container, false)
return _binding?.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.inputZone.setText(AdmobKeys.APP_OPEN)
binding.btnRequest.setOnClickListener {
requestAd()
}
binding.btnShow.setOnClickListener {
showAd()
}

lifecycleScope.launch(Dispatchers.Main) {
viewModel.logMessage.collect {
binding.tvLog.text = it
}
}
}

private fun requestAd() {
viewModel.requestAd(binding.inputZone.text.toString())
}

private fun showAd() {
viewModel.showAd(requireActivity())
}

override fun onDestroy() {
super.onDestroy()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ir.tapsell.sample.appopen

import android.util.Log
import androidx.fragment.app.FragmentActivity
import ir.tapsell.mediation.Tapsell
import ir.tapsell.mediation.ad.AdStateListener
import ir.tapsell.mediation.ad.request.RequestResultListener
import ir.tapsell.mediation.ad.show.AdShowCompletionState
import ir.tapsell.sample.BaseViewModel

class AppOpenViewModel : BaseViewModel() {

companion object {
private const val TAG = "AppOpenViewModel"
}

var responseId: String? = null
private set


fun requestAd(zoneId: String) {
Tapsell.requestAppOpenAd(zoneId, object : RequestResultListener {
override fun onFailure() {
log(TAG, "onFailure", Log.ERROR)
}

override fun onSuccess(adId: String) {
responseId = adId
log(TAG, "onSuccess: $adId")
}
})
}

fun showAd(activity: FragmentActivity) {
if (responseId.isNullOrEmpty()) {
log(TAG, "adId is empty", Log.ERROR)
return
}
Tapsell.showAppOpenAd(responseId, activity, object : AdStateListener.AppOpen {
override fun onAdClicked() {
log(TAG, "onAdClicked")
}

override fun onAdClosed(completionState: AdShowCompletionState) {
log(TAG, "onAdClosed: ${completionState.name}")
}

override fun onAdFailed(message: String) {
log(TAG, "onAdFailed: $message", Log.ERROR)
}

override fun onAdImpression() {
log(TAG, "onAdImpression")
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class HomeFragment : Fragment() {
binding.btnInterstitial.setOnClickListener {
navController.navigate(R.id.action_fragment_home_to_fragment_interstitial)
}
binding.btnAppOpen.setOnClickListener {
navController.navigate(R.id.action_fragment_home_to_fragment_app_open)
}
binding.btnStandardBanner.setOnClickListener {
navController.navigate(R.id.action_fragment_home_to_fragment_standard_banner)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InterstitialFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.inputZone.setText(TapsellMediationKeys.INTERSTITIAL)
binding.btnRequest.setOnClickListener {
requestAd()
}
Expand All @@ -44,7 +45,7 @@ class InterstitialFragment : Fragment() {
}

private fun requestAd() {
viewModel.requestAd(TapsellMediationKeys.INTERSTITIAL)
viewModel.requestAd(binding.inputZone.text.toString())
}

private fun showAd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class NativeBannerFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.inputZone.setText(TapsellMediationKeys.NATIVE)
binding.btnRequest.setOnClickListener {
requestAd()
}
Expand All @@ -50,7 +51,7 @@ class NativeBannerFragment : Fragment() {
}

private fun requestAd(count: Int = 1) {
viewModel.requestAd(TapsellMediationKeys.NATIVE, count)
viewModel.requestAd(binding.inputZone.text.toString(), count)
}

private fun showAd() = NativeAdViewContainer(requireContext()).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PreRollFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.inputZone.setText(TapsellMediationKeys.PRE_ROLL)
binding.btnRequest.setOnClickListener {
requestAd()
}
Expand All @@ -56,7 +57,7 @@ class PreRollFragment : Fragment() {

private fun requestAd() {
viewModel.requestAd(
zoneId = TapsellMediationKeys.PRE_ROLL,
zoneId = binding.inputZone.text.toString(),
container = binding.videoPlayerContainer,
companionContainer = binding.companionContainer, // optional
videoPlayer = binding.exoPlayer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RewardedVideoFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.inputZone.setText(TapsellMediationKeys.REWARDED)
binding.btnRequest.setOnClickListener {
requestAd()
}
Expand All @@ -44,7 +45,7 @@ class RewardedVideoFragment : Fragment() {
}

private fun requestAd() {
viewModel.requestAd(TapsellMediationKeys.REWARDED)
viewModel.requestAd(binding.inputZone.text.toString())
}

private fun showAd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class StandardBannerFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.inputZone.setText(AdmobKeys.BANNER)
binding.btnRequest.setOnClickListener {
requestAd()
}
Expand All @@ -48,7 +49,7 @@ class StandardBannerFragment : Fragment() {

private fun requestAd() {
viewModel.requestAd(
AdmobKeys.BANNER,
binding.inputZone.text.toString(),
BannerSize.BANNER_ADAPTIVE
)
}
Expand Down
49 changes: 49 additions & 0 deletions sample-kotlin/src/main/res/layout/fragment_app_open.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:padding="@dimen/space_small"
tools:context=".appopen.AppOpenFragment">

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_request"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/request"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/space_small"
android:text="@string/show"
app:layout_constraintTop_toBottomOf="@+id/btn_request" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/tv_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:background="#ddd"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_show" />

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_zone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/zone_id"
android:textColor="@android:color/darker_gray"
android:textSize="@dimen/h6"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
13 changes: 11 additions & 2 deletions sample-kotlin/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/space_small"
android:text="@string/interstitial"
app:layout_constraintBottom_toTopOf="@+id/btn_native_banner"
app:layout_constraintBottom_toTopOf="@+id/btn_app_open"
app:layout_constraintTop_toBottomOf="@+id/btn_rewarded_video" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_app_open"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/space_small"
android:text="@string/app_open"
app:layout_constraintBottom_toTopOf="@+id/btn_native_banner"
app:layout_constraintTop_toBottomOf="@+id/btn_interstitial" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_native_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/space_small"
android:text="@string/native_banner"
app:layout_constraintBottom_toTopOf="@+id/btn_standard_banner"
app:layout_constraintTop_toBottomOf="@+id/btn_interstitial" />
app:layout_constraintTop_toBottomOf="@+id/btn_app_open" />

<com.google.android.material.button.MaterialButton
android:id="@+id/btn_standard_banner"
Expand Down
Loading

0 comments on commit b2aea8a

Please sign in to comment.