Native plugin setup replaces the standard Monetizr Unity plugin library with its Android library. It allows using Google Pay within mobile Unity games.
Requires Android Studio. Tested with Unity 2017.2.5f1 and Unity 2019.3.0f3.
The Android project structure has slight differences between various Unity versions, but the workflow remains largely the same.
Enable the native plugin
In the Monetizr settings window (Window > Monetizr Settings) enable Android native plugin. This will enable ShowProductForTag
calls to call the native Android plugin on builds.


Export your project
In order to add the Monetizr Android plugin to your project, you will have to perform a few additional steps each time you wish to make a build of your application.
Your application needs to be exported into Android project that can be opened with Android Studio. You can do that from the Build Settings window.


Open the project with Android Studio
Open the exported project with Android Studio. Upon opening, you might see this message - click OK.


Make the necessary file changes
The Unity Android build process has been changing over time. These instructions assume that the current MonetizrSDK version is 2.1.0
, however a newer version may be available - you can check here
For Unity 2019 project
- Edit the
build.gradle
file found in theunityLibrary
module. To the dependencies section add these dependencies:
implementation 'io.monetizr.monetizrsdk:MonetizrSDK:2.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
In all build.gradle
files If minSdkVersion
is less than 26
, change it to minSdkVersion 26
.
- Edit the project-wide
build.gradle
file. Add another repository from which to get dependencies. In theallprojects -> repositories
section addmavenCentral()
. It should end up similar to this:
repositories {
google()
mavenCentral()
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}
In the android
block add this block (note - this may no longer be required since Unity 2019.4):
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
After these steps, Gradle sync will be successful, however, the project still won't build.
- Edit the
gradle.properties
file. Add the following:
android.useAndroidX=true
android.enableJetifier=true
After this step, the build will be successful, however, there is still one last step.
- Edit the
AndroidManifest.xml
file found in theunityLibrary
module. In the<activity>
tag, change the value for propertyandroid:theme
to@style/Theme.AppCompat.DayNight
.
As per the Android plugin setup instructions add a new meta-data
entry for your access token.
<meta-data android:name="monetizr_api_key" android:value="4D2E54389EB489966658DDD83E2D1"/>
- Congratulations, the native plugin is up and running!
For Unity 2017 project
- Edit the
gradle-wrapper.properties
file. Make sure thedistributionUrl
line corresponds to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
- Edit the
build.gradle
file. In thebuildscript -> dependencies
section change thebuild:gradle
entry to this:
classpath 'com.android.tools.build:gradle:3.4.0'
Moving lower in the file after the apply-plugin
line add this:
repositories {
google()
mavenCentral()
jcenter()
}
Also, add these repositories to the buildscript
block on top of the file.
To the dependencies section that is not within buildscript
block add these dependencies:
implementation 'io.monetizr.monetizrsdk:MonetizrSDK:2.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
In the android
block add this block:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Finally, increase the minSdkVersion to at least 26
-
Perform a Gradle sync - you should receive an error. Android Studio will offer you a fix for this error (Move minSdkVersion to build file and sync project) - perform the fix. At this point, the Gradle sync should be successful.
-
Edit the
gradle.properties
file. Add the following:
android.useAndroidX=true
android.enableJetifier=true
After this step, the build will be successful, however, there is still one last step.
- Edit the project's
AndroidManifest.xml
file. In the<application>
tag, change the value for propertyandroid:theme
to@style/Theme.AppCompat.DayNight
.
As per the Android plugin setup instructions add a new meta-data
entry for your access token.
<meta-data android:name="monetizr_api_key" android:value="4D2E54389EB489966658DDD83E2D1"/>
- Congratulations, the native plugin is up and running!
If you are experiencing issues with installing the APK on your device try reducing the targetSdkVersion
, and respectively - compileSdkVersion
and buildToolsVersion
.
Updated 6 months ago