Skip to content

Commit 747aeab

Browse files
LTPhantomcopybara-github
authored andcommitted
Updating UnityAds Flutter mediation plugin to support the latest adapters (4.17.0.0, 4.17.0.0)
PiperOrigin-RevId: 906312924
1 parent 1262990 commit 747aeab

10 files changed

Lines changed: 245 additions & 122 deletions

File tree

packages/mediation/gma_mediation_unity/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unity Ads Flutter Mediation Adapter Changelog
22

3+
#### Version 1.7.0 (In progress)
4+
- Updated minimum Flutter version to 3.38.1
5+
- Updated to support Google Mobile Ads Flutter Plugin version 8.0.0
6+
37
#### Version 1.6.5
48
- Supports [Unity Android adapter version 4.16.6.0](https://github.com/googleads/googleads-mobile-android-mediation/blob/main/ThirdPartyAdapters/unity/CHANGELOG.md#version-41660).
59
- Supports [Unity iOS adapter version 4.16.6.0](https://github.com/googleads/googleads-mobile-ios-mediation/blob/main/adapters/Unity/CHANGELOG.md#version-41660).

packages/mediation/gma_mediation_unity/android/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
group 'io.flutter.plugins.googlemobileads.mediation.gma_mediation_unity'
2-
version = "1.6.5"
2+
version = "1.7.0"
33

44
buildscript {
5-
ext.kotlin_version = '2.2.21'
5+
ext.kotlin_version = '2.3.0'
66
repositories {
77
google()
88
mavenCentral()
@@ -25,7 +25,7 @@ apply plugin: 'com.android.library'
2525
apply plugin: 'kotlin-android'
2626

2727
ext {
28-
stringVersion = "4.16.6.0"
28+
stringVersion = "4.17.0.0"
2929
}
3030

3131
android {
@@ -55,8 +55,9 @@ android {
5555
}
5656

5757
dependencies {
58-
implementation 'com.unity3d.ads:unity-ads:4.16.3'
58+
implementation 'com.unity3d.ads:unity-ads:4.17.0'
5959
implementation "com.google.ads.mediation:unity:$stringVersion"
60+
implementation 'com.google.android.gms:play-services-ads:25.1.0'
6061
testImplementation 'junit:junit:4.13.2'
6162
testImplementation 'androidx.test:core:1.5.0'
6263
testImplementation 'androidx.test:core-ktx:1.5.0'

packages/mediation/gma_mediation_unity/android/src/main/kotlin/io/flutter/plugins/googlemobileads/mediation/gma_mediation_unity/UnityPrivacyApi.g.kt

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// Autogenerated from Pigeon (v18.0.0), do not edit directly.
1+
// Autogenerated from Pigeon (v26.3.4), do not edit directly.
22
// See also: https://pub.dev/packages/pigeon
3+
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")
34

45
package io.flutter.plugins.googlemobileads.mediation.gma_mediation_unity
56

@@ -11,89 +12,118 @@ import io.flutter.plugin.common.StandardMessageCodec
1112
import java.io.ByteArrayOutputStream
1213
import java.nio.ByteBuffer
1314

14-
private fun wrapResult(result: Any?): List<Any?> {
15-
return listOf(result)
16-
}
15+
private object UnityPrivacyApiPigeonUtils {
16+
17+
fun wrapResult(result: Any?): List<Any?> {
18+
return listOf(result)
19+
}
1720

18-
private fun wrapError(exception: Throwable): List<Any?> {
19-
if (exception is FlutterError) {
20-
return listOf(
21-
exception.code,
22-
exception.message,
23-
exception.details
24-
)
25-
} else {
26-
return listOf(
27-
exception.javaClass.simpleName,
28-
exception.toString(),
29-
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
30-
)
21+
fun wrapError(exception: Throwable): List<Any?> {
22+
return if (exception is FlutterError) {
23+
listOf(exception.code, exception.message, exception.details)
24+
} else {
25+
listOf(
26+
exception.javaClass.simpleName,
27+
exception.toString(),
28+
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception),
29+
)
30+
}
3131
}
3232
}
3333

3434
/**
3535
* Error class for passing custom error details to Flutter via a thrown PlatformException.
36+
*
3637
* @property code The error code.
3738
* @property message The error message.
3839
* @property details The error details. Must be a datatype supported by the api codec.
3940
*/
40-
class FlutterError (
41+
class FlutterError(
4142
val code: String,
4243
override val message: String? = null,
43-
val details: Any? = null
44-
) : Throwable()
44+
val details: Any? = null,
45+
) : RuntimeException()
46+
47+
private open class UnityPrivacyApiPigeonCodec : StandardMessageCodec() {
48+
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
49+
return super.readValueOfType(type, buffer)
50+
}
51+
52+
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
53+
super.writeValue(stream, value)
54+
}
55+
}
56+
4557
/**
46-
* The generated classes set the channels to call the methods in the corresponding kotlin UnityPrivacyApi interface and swift UnityPrivacyApi protocol from the dart layer.
58+
* The generated classes set the channels to call the methods in the corresponding kotlin
59+
* UnityPrivacyApi interface and swift UnityPrivacyApi protocol from the dart layer.
4760
*
4861
* Generated interface from Pigeon that represents a handler of messages from Flutter.
4962
*/
5063
interface UnityPrivacyApi {
5164
/** Used to configure GDPR consent on the Android or iOS Unity SDK */
5265
fun setGDPRConsent(gdprConsent: Boolean)
66+
5367
/** Used to configure CCPA consent on the Android or iOS Unity SDK */
5468
fun setCCPAConsent(ccpaConsent: Boolean)
5569

5670
companion object {
5771
/** The codec used by UnityPrivacyApi. */
58-
val codec: MessageCodec<Any?> by lazy {
59-
StandardMessageCodec()
60-
}
61-
/** Sets up an instance of `UnityPrivacyApi` to handle messages through the `binaryMessenger`. */
62-
@Suppress("UNCHECKED_CAST")
63-
fun setUp(binaryMessenger: BinaryMessenger, api: UnityPrivacyApi?, messageChannelSuffix: String = "") {
64-
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
72+
val codec: MessageCodec<Any?> by lazy { UnityPrivacyApiPigeonCodec() }
73+
74+
/**
75+
* Sets up an instance of `UnityPrivacyApi` to handle messages through the `binaryMessenger`.
76+
*/
77+
@JvmOverloads
78+
fun setUp(
79+
binaryMessenger: BinaryMessenger,
80+
api: UnityPrivacyApi?,
81+
messageChannelSuffix: String = "",
82+
) {
83+
val separatedMessageChannelSuffix =
84+
if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
6585
run {
66-
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setGDPRConsent$separatedMessageChannelSuffix", codec)
86+
val channel =
87+
BasicMessageChannel<Any?>(
88+
binaryMessenger,
89+
"dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setGDPRConsent$separatedMessageChannelSuffix",
90+
codec,
91+
)
6792
if (api != null) {
6893
channel.setMessageHandler { message, reply ->
6994
val args = message as List<Any?>
7095
val gdprConsentArg = args[0] as Boolean
71-
var wrapped: List<Any?>
72-
try {
73-
api.setGDPRConsent(gdprConsentArg)
74-
wrapped = listOf<Any?>(null)
75-
} catch (exception: Throwable) {
76-
wrapped = wrapError(exception)
77-
}
96+
val wrapped: List<Any?> =
97+
try {
98+
api.setGDPRConsent(gdprConsentArg)
99+
listOf(null)
100+
} catch (exception: Throwable) {
101+
UnityPrivacyApiPigeonUtils.wrapError(exception)
102+
}
78103
reply.reply(wrapped)
79104
}
80105
} else {
81106
channel.setMessageHandler(null)
82107
}
83108
}
84109
run {
85-
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setCCPAConsent$separatedMessageChannelSuffix", codec)
110+
val channel =
111+
BasicMessageChannel<Any?>(
112+
binaryMessenger,
113+
"dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setCCPAConsent$separatedMessageChannelSuffix",
114+
codec,
115+
)
86116
if (api != null) {
87117
channel.setMessageHandler { message, reply ->
88118
val args = message as List<Any?>
89119
val ccpaConsentArg = args[0] as Boolean
90-
var wrapped: List<Any?>
91-
try {
92-
api.setCCPAConsent(ccpaConsentArg)
93-
wrapped = listOf<Any?>(null)
94-
} catch (exception: Throwable) {
95-
wrapped = wrapError(exception)
96-
}
120+
val wrapped: List<Any?> =
121+
try {
122+
api.setCCPAConsent(ccpaConsentArg)
123+
listOf(null)
124+
} catch (exception: Throwable) {
125+
UnityPrivacyApiPigeonUtils.wrapError(exception)
126+
}
97127
reply.reply(wrapped)
98128
}
99129
} else {

packages/mediation/gma_mediation_unity/example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '2.2.21'
2+
ext.kotlin_version = '2.3.0'
33
repositories {
44
google()
55
mavenCentral()

packages/mediation/gma_mediation_unity/example/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pluginManagement {
2424
plugins {
2525
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
2626
id "com.android.application" version "8.13.1" apply false
27-
id 'org.jetbrains.kotlin.android' version '2.2.21' apply false
27+
id 'org.jetbrains.kotlin.android' version '2.3.0' apply false
2828
}
2929

3030
include ":app"

packages/mediation/gma_mediation_unity/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ description: "Demonstrates how to use the gma_mediation_unity plugin."
55
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
66

77
environment:
8-
sdk: '>=3.9.0 <4.0.0'
8+
sdk: '>=3.10.0 <4.0.0'
99

1010
dependencies:
1111
flutter:
1212
sdk: flutter
1313

14-
google_mobile_ads: ^7.0.0
14+
google_mobile_ads: ^8.0.0
1515
gma_mediation_unity:
1616
path: ../
1717

packages/mediation/gma_mediation_unity/ios/Classes/UnityPrivacyApi.g.swift

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Autogenerated from Pigeon (v18.0.0), do not edit directly.
1+
// Autogenerated from Pigeon (v26.3.4), do not edit directly.
22
// See also: https://pub.dev/packages/pigeon
33

44
import Foundation
@@ -11,11 +11,36 @@ import Foundation
1111
#error("Unsupported platform.")
1212
#endif
1313

14+
/// Error class for passing custom error details to Dart side.
15+
final class PigeonError: Error {
16+
let code: String
17+
let message: String?
18+
let details: Sendable?
19+
20+
init(code: String, message: String?, details: Sendable?) {
21+
self.code = code
22+
self.message = message
23+
self.details = details
24+
}
25+
26+
var localizedDescription: String {
27+
return
28+
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
29+
}
30+
}
31+
1432
private func wrapResult(_ result: Any?) -> [Any?] {
1533
return [result]
1634
}
1735

1836
private func wrapError(_ error: Any) -> [Any?] {
37+
if let pigeonError = error as? PigeonError {
38+
return [
39+
pigeonError.code,
40+
pigeonError.message,
41+
pigeonError.details,
42+
]
43+
}
1944
if let flutterError = error as? FlutterError {
2045
return [
2146
flutterError.code,
@@ -25,7 +50,7 @@ private func wrapError(_ error: Any) -> [Any?] {
2550
}
2651
return [
2752
"\(error)",
28-
"\(type(of: error))",
53+
"\(Swift.type(of: error))",
2954
"Stacktrace: \(Thread.callStackSymbols)",
3055
]
3156
}
@@ -38,6 +63,28 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
3863
if value is NSNull { return nil }
3964
return value as! T?
4065
}
66+
67+
private class UnityPrivacyApiPigeonCodecReader: FlutterStandardReader {
68+
}
69+
70+
private class UnityPrivacyApiPigeonCodecWriter: FlutterStandardWriter {
71+
}
72+
73+
private class UnityPrivacyApiPigeonCodecReaderWriter: FlutterStandardReaderWriter {
74+
override func reader(with data: Data) -> FlutterStandardReader {
75+
return UnityPrivacyApiPigeonCodecReader(data: data)
76+
}
77+
78+
override func writer(with data: NSMutableData) -> FlutterStandardWriter {
79+
return UnityPrivacyApiPigeonCodecWriter(data: data)
80+
}
81+
}
82+
83+
class UnityPrivacyApiPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
84+
static let shared = UnityPrivacyApiPigeonCodec(
85+
readerWriter: UnityPrivacyApiPigeonCodecReaderWriter())
86+
}
87+
4188
/// The generated classes set the channels to call the methods in the corresponding kotlin UnityPrivacyApi interface and swift UnityPrivacyApi protocol from the dart layer.
4289
///
4390
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
@@ -50,12 +97,17 @@ protocol UnityPrivacyApi {
5097

5198
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
5299
class UnityPrivacyApiSetup {
53-
/// The codec used by UnityPrivacyApi.
100+
static var codec: FlutterStandardMessageCodec { UnityPrivacyApiPigeonCodec.shared }
54101
/// Sets up an instance of `UnityPrivacyApi` to handle messages through the `binaryMessenger`.
55-
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: UnityPrivacyApi?, messageChannelSuffix: String = "") {
102+
static func setUp(
103+
binaryMessenger: FlutterBinaryMessenger, api: UnityPrivacyApi?,
104+
messageChannelSuffix: String = ""
105+
) {
56106
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
57107
/// Used to configure GDPR consent on the Android or iOS Unity SDK
58-
let setGDPRConsentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setGDPRConsent\(channelSuffix)", binaryMessenger: binaryMessenger)
108+
let setGDPRConsentChannel = FlutterBasicMessageChannel(
109+
name: "dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setGDPRConsent\(channelSuffix)",
110+
binaryMessenger: binaryMessenger, codec: codec)
59111
if let api = api {
60112
setGDPRConsentChannel.setMessageHandler { message, reply in
61113
let args = message as! [Any?]
@@ -71,7 +123,9 @@ class UnityPrivacyApiSetup {
71123
setGDPRConsentChannel.setMessageHandler(nil)
72124
}
73125
/// Used to configure CCPA consent on the Android or iOS Unity SDK
74-
let setCCPAConsentChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setCCPAConsent\(channelSuffix)", binaryMessenger: binaryMessenger)
126+
let setCCPAConsentChannel = FlutterBasicMessageChannel(
127+
name: "dev.flutter.pigeon.gma_mediation_unity.UnityPrivacyApi.setCCPAConsent\(channelSuffix)",
128+
binaryMessenger: binaryMessenger, codec: codec)
75129
if let api = api {
76130
setCCPAConsentChannel.setMessageHandler { message, reply in
77131
let args = message as! [Any?]

packages/mediation/gma_mediation_unity/ios/gma_mediation_unity.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
Pod::Spec.new do |s|
66
s.name = 'gma_mediation_unity'
7-
s.version = '1.6.5'
7+
s.version = '1.7.0'
88
s.summary = 'Google Mobile Ads Mediation of Unity Ads.'
99
s.description = <<-DESC
1010
Mediation Adapter for Unity Ads to use with Google Mobile Ads.
@@ -16,12 +16,12 @@ Mediation Adapter for Unity Ads to use with Google Mobile Ads.
1616
s.source_files = 'Classes/**/*'
1717
s.public_header_files = 'Classes/**/*.h'
1818
s.dependency 'Flutter'
19-
s.dependency 'GoogleMobileAdsMediationUnity', '~>4.16.6.0'
19+
s.dependency 'GoogleMobileAdsMediationUnity', '~>4.17.0.0'
2020
s.platform = :ios, '13.0'
2121
s.static_framework = true
2222

2323
# Flutter.framework does not contain a i386 slice.
2424
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
25-
s.swift_version = '5.0'
25+
s.swift_version = '6.0'
2626

2727
end

0 commit comments

Comments
 (0)