Search Unity

Writing a preference activity wrapper for android project (exported from unity)

Discussion in 'Scripting' started by DoomDude99, Aug 29, 2019.

  1. DoomDude99

    DoomDude99

    Joined:
    May 11, 2019
    Posts:
    87
    When exporting a project, an android project is generated with the following entries in its manifest file:

    Code (CSharp):
    1.     <application>    
    2.         <meta-data
    3.             android:name="com.google.android.gms.ads.APPLICATION_ID"
    4.             android:value="@string/admob_app_id"/>
    5.  
    6.         <!-- This is to be extended with an activity that handles in app purchases -->
    7.         <activity
    8.             android:name="com.co.android.unityplugin.PreferencesActivity"
    9.             android:exported="true"
    10.             android:hardwareAccelerated="true"
    11.             android:windowSoftInputMode="adjustPan" >
    12.         </activity> <!-- Without explicit hardwareAccelerated="true" , preference activity scrolling was very slow -->
    I need to write a custom in app purchase mechanism since unity doesn't support IAP for live wallpapers (the project is using a plugin to this end).

    Right now, I'm thinking of extending "com.co.android.unityplugin.PreferencesActivity" with a custom activity that does the IAP handling and created a separate module in the exported android project but can't seem to be able to access PreferencesActiviy:

    Code (CSharp):
    1. error: package com.co.android.unityplugin.PreferencesActivity does not exist.
    I followed the suggestions at:

    https://stackoverflow.com/questions...t-class-from-another-module-in-android-studio

    Code (CSharp):
    1. allprojects {
    2.     buildscript {
    3.         repositories {
    4.             google()
    5.             jcenter()
    6.         }
    7.  
    8.         dependencies {
    9.             classpath 'com.android.tools.build:gradle:3.4.2'
    10.             compile project(':iappreferencemodule') // <== this is the module that handles IAP and was added
    11.                                                                             //        as a dependency to all android bundles
    12.         }
    but got:

    Code (CSharp):
    1. ERROR: Could not find method compile() for arguments
    and suggestions such as:

    https://stackoverflow.com/questions/27617687/gradle-dsl-method-not-found-compile

    do not seem to be helpful in building the project. Is this the right way of extending preference activities?