unity接入华为sdk之使用unity插件

unity针对华为 提供了专门的插件

插件下载地址:https://assetstore.unity.com/packages/add-ons/services/huawei-hms-core-app-services-176968

demo下载地址:https://github.com/Unity-Technologies/HMSSDKSample

官方文档:https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/appgallery.html

这个demo是无法打包的 打包会报错 需将Plugins/Android下面的三个gradle进行合并

unity接入华为sdk之使用unity插件_第1张图片

合并成一个mainTemplate

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN

buildscript {
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
        flatDir {
            dirs 'libs'
        }
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.huawei.hms:base:5.0.3.300'
    implementation 'com.huawei.hms:hwid:5.0.3.301'
    implementation 'com.huawei.hms:game:5.0.3.301'
    implementation 'com.huawei.agconnect:agconnect-auth:1.4.1.300'
    implementation 'com.huawei.hms:hianalytics:5.0.4.300'
}

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.3'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 29
        applicationId 'xxx.xxx.xxx'
        ndk {
            abiFilters 'armeabi-v7a'
        }
        versionCode 1
        versionName '0.1'
    }

    signingConfigs {
       release {
           storeFile file("../../xxx.keystore")
           storePassword "xxxx"
           keyAlias "xxx"
           keyPassword "xxxx"
       }
   }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb']
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

    buildTypes {
        debug {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            signingConfig signingConfigs.release
            jniDebuggable true
        }
        release {
            minifyEnabled false
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
            signingConfig signingConfigs.release
        }
    }

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
    }


    bundle {
        language {
            enableSplit = false
        }
        density {
            enableSplit = false
        }
        abi {
            enableSplit = true
        }
    }
}

这样就能打出包 打包过程 此处不解释

但是运行打出的apk会遇到以下问题

unity接入华为sdk之使用unity插件_第2张图片

通过as解开apk 你会发现 里面缺少上面报错的包 那是下面的两个aar包 没有被打进apk

unity接入华为sdk之使用unity插件_第3张图片
解决办法 在上面的gradle里面 加入一行代码 将aar包一起打进去
implementation fileTree(dir: 'libs', include: ['*.aar'])

unity接入华为sdk之使用unity插件_第4张图片

通过上面 一行代码 搞定

这个插件是unity提供的 最终要通过udp平台发布出去 包括支付也要使用unity的支付 具体的看unity文档

https://docs.unity3d.com/Packages/[email protected]/manual/creating-a-game-on-udp.html

https://distribute.dashboard.unity.com/udp/guideDoc/HUAWEI#Anchor=Mandatory

你可能感兴趣的:(unity,华为)