Android JUnion SDK 集成指南

SDK 集成 - Vaas

添加SDK到工程中

  • 解压缩 junion-android-X.X.X-release.zip 集成压缩包。
  • 复制libs/* 到工程 libs/ 目录下。

在App.gradle中加入maven仓库地址

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        //添加阿里云maven地址
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
        }
    }
}

在使用的module中加入依赖,具体sdk版本根据发布的文档为准


//在gradle的Android节点下添加,如下
android {
    ...
    ...
    defaultConfig {
        applicationId "你的包名"
        ...
        ...

        multiDexEnabled true
        ndk {
            abiFilters 'armeabi-v7a'
        }
        manifestPlaceholders = [
                // 设置manifest.xml中的变量
                JPUSH_PKGNAME: applicationId,
                JPUSH_APPKEY :  "你的 Appkey ", //Portal上注册的包名对应的 appKey.
                JPUSH_CHANNEL:  "developer-default", //暂时填写默认值即可.
        ]
    }
    repositories {
        flatDir {
            dirs "libs", "libs"
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}
dependencies {
        ......
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.squareup.okhttp3:okhttp:3.11.0'
        implementation 'com.google.code.gson:gson:2.8.5'
        implementation 'com.android.support:recyclerview-v7:28.0.0'
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support:support-v4:28.0.0'

        implementation ('com.aliyun.ams:alicloud-android-httpdns:1.2.3@aar') {
            transitive true
        }
        //支持ijkplayer进行播放,非必选,建议添加,否则有可能无法检测到全部的播放状态
        implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
        implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8'
        //implementation 'tv.danmaku.ijk.media:ijkplayer-armv5:0.8.8'
        //implementation 'tv.danmaku.ijk.media:ijkplayer-arm64:0.8.8'
        //implementation 'tv.danmaku.ijk.media:ijkplayer-x86:0.8.8'
        //implementation 'tv.danmaku.ijk.media:ijkplayer-x86_64:0.8.8'

        implementation(name:'junion-android-${SDK_VERSION}', ext:'aar')//修改为具体的sdk版本

        //支持第三方广告,非必选
        //广点通广告
        api(name:'gdt-4.291', ext:'aar')
        //穿山甲
        api(name:'open_ad_sdk', ext:'aar')
        //快手
        api(name:'kssdk-ad-3.3.3', ext:'aar')
        ......
}

AndroidManifest.xml


        <!-- Required -->
        <meta-data
            android:name="JPUSH_APPKEY"
            android:value="${JPUSH_APPKEY}" /> <!-- </>值来自开发者平台取得的AppKey -->
        <meta-data
            android:name="JPUSH_CHANNEL"
            android:value="${JPUSH_CHANNEL}" />


        <!-- 穿山甲 start-->
        <provider
            android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
            android:authorities="${applicationId}.TTFileProvider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/jg_byte_file_paths" />
        </provider>

        <provider
            android:name="com.bytedance.sdk.openadsdk.multipro.TTMultiProvider"
            android:authorities="${applicationId}.TTMultiProvider"
            android:exported="false" />
        <!-- 穿山甲 end-->

        <!-- 广点通 start-->
                <provider
                    android:name="com.qq.e.comm.GDTFileProvider"
                    android:authorities="${applicationId}.gdt.fileprovider"
                    android:exported="false"
                    android:grantUriPermissions="true">
                    <meta-data
                        android:name="android.support.FILE_PROVIDER_PATHS"
                        android:resource="@xml/gdt_file_path" />
                </provider>
                <!-- 声明 SDK 所需要的组件 -->
                <service
                    android:name="com.qq.e.comm.DownloadService"
                    android:exported="false" />
                <!-- 请开发者注意字母的大小写,ADActivity,而不是 AdActivity -->
                <activity
                    android:name="com.qq.e.ads.ADActivity"
                    android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />
                <activity
                    android:name="com.qq.e.ads.PortraitADActivity"
                    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
                    android:screenOrientation="portrait" />
                <activity
                    android:name="com.qq.e.ads.LandscapeADActivity"
                    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
                    android:screenOrientation="sensorLandscape" />
        <!-- 广点通 end-->
    <!-- 快手 start-->
    <permission
        android:name="${applicationId}.permission.KW_SDK_BROADCAST"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.KW_SDK_BROADCAST" />
    <!-- 快手 end-->

混淆

若您的App开启了混淆,请为我们的SDK添加下述混淆规则

-keep class cn.jiguang.**{
    *;
}
-dontwarn javax.annotation.**
-dontwarn sun.misc.Unsafe
-dontwarn org.conscrypt.*
-dontwarn okio.**

###阿里云混淆
-keep class com.alibaba.sdk.android.**{*;}
-keep class com.ut.**{*;}
-keep class com.ta.**{*;}


###其他混淆
-keep class com.bytedance.sdk.openadsdk.** { *; }
-keep public interface com.bytedance.sdk.openadsdk.downloadnew.** {*;}
-keep class com.pgl.sys.ces.* {*;}

-keep class com.qq.e.** {
    public protected *;
}
-keep class android.support.v4.**{
    public *;
}
-keep class android.support.v7.**{
    public *;
}


-keep class org.chromium.** {*;}
-keep class org.chromium.** { *; }
-keep class aegon.chrome.** { *; }
-keep class com.kwai.**{ *; }
-dontwarn com.kwai.**
-dontwarn com.kwad.**
-dontwarn com.ksad.**
-dontwarn aegon.chrome.**


-keepclassmembers class * extends android.app.Activity { public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class com.baidu.mobads.*.** { *; }

如果您的应用启用了资源混淆或资源缩减,您需要保留SDK的资源,SDK的资源名都是以ksad_开头的。您可以在资源混淆配置⽂文件添加如下配置:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="@layout/ksad_*,@id/ksad_*,@style/ksad_*,
@drawable/ksad_*,@string/ksad_*,@color/ksad_*,@attr/ksad_*,@dimen/ksad_*"
/>

冲突解决

1、图片加载库异常,编译不通过

More than one file was found with OS independent path 'lib/armeabi-v7a/libRSSupport.so'

android {
    packagingOptions {

        exclude 'lib/*/libRSSupport.so'

        exclude 'lib/*/librsjni.so'
    }
}

2、当小视频fragment有嵌套时可能会有界面切换时视频在后台播放的情况,解决方法:在fragment的onHiddenChanged中调用LittleVideoFragment的onHiddenChangedfragment ```


Copyright 2011-2020, jiguang.cn, All Rights Reserved.
粤ICP备12056275号-13 深圳市和讯华谷信息技术有限公司

Documentation built with MkDocs.