推荐Gradle接入方式
1.仓库 Project:build.gradle
allprojects {
repositories {
jcenter()
maven {
url "http://repo.baichuan-android.taobao.com/content/groups/BaichuanRepositories/"
}
}
}
2.依赖 Module:build.gradle
dependencies {
//gson
implementation 'com.google.code.gson:gson:2.8.0'
//fastjson
implementation 'com.alibaba:fastjson:1.2.9'
//支付
implementation 'com.alibaba.alipay:alipaySingle:20160825@jar'
//登陆
implementation 'com.ali.auth.sdk:alibabauth_core:1.1.4@jar'
implementation 'com.ali.auth.sdk:alibabauth_ui:1.1.4@aar'
implementation 'com.ali.auth.sdk:alibabauth_ext:1.1.4@jar'
//【可选】仅供特殊合作伙伴使用
implementation 'com.ali.auth.sdk:alibabauth_accountlink:1.1.4@jar'
//安全基础
implementation 'com.taobao.android:securityguardaar3:5.1.81@aar'
//【可选】安全高级,如使用了发放红包、优惠券高级功能,则必须引入
implementation 'com.taobao.android:securitybodyaar3:5.1.25@aar'
//Mtop网关
implementation 'com.taobao.android:mtopsdk_allinone_open:1.2.2.4@jar'
//applink
implementation 'com.alibaba.sdk.android:alibc_link_partner:1.1.0.6'
//UT
implementation 'com.taobao.android:utdid4all:1.1.5.3_proguard@jar'
implementation 'com.alibaba.mtl:app-monitor-sdk:2.5.1.3_for_bc_proguard@jar'
//联盟SDK
implementation 'com.alimama.tunion.sdk:tuniontradesdk:0.3.2@aar'
//电商SDK
implementation 'com.alibaba.sdk.android:alibc_trade_common:3.1.1.221'
implementation 'com.alibaba.sdk.android:alibc_trade_biz:3.1.1.221'
implementation 'com.alibaba.sdk.android:alibc_trade_sdk:3.1.1.221'
}
3.清单文件 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:allowBackup">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<!--设置淘宝登录页面Activity的样式-->
<activity
android:name="com.ali.auth.third.ui.LoginActivity"
android:theme="@style/SwbTransparentLight"
tools:replace="android:theme" />
</application>
附:SwbTransparentLight
<style name="SwbTransparentLight" parent="AppTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">false</item>
</style>
4.混淆 Proguard Rules for app
#阿里百川
-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
-keep class com.alibaba.** {*;}
-dontwarn com.alibaba.**
-keep class com.alipay.** {*;}
-dontwarn com.alipay.**
-keep class com.taobao.** {*;}
-dontwarn com.taobao.**
-keep class com.ut.** {*;}
-dontwarn com.ut.**
-keep class com.ta.** {*;}
-dontwarn com.ta.**
-keep class mtopsdk.** {*;}
-dontwarn mtopsdk.**
-keep class org.json.** {*;}
-keep class com.ali.auth.** {*;}
-dontwarn com.ali.auth.**
-dontwarn com.alimama.**
-keep class com.alimama.** {*;}
-keeppackagenames com.alimama.tunion.sdk.**
-keeppackagenames com.alimama.tunion.sdk.**
-keep class com.alimama.tunion.sdk.** {
public <fields>;
public <methods>;
}
5.安全图片
获得安全图片(图片获取方式见接入准备文档),并放在/res/drawable目录下,如果已经有安全图片,需要替换。
6.初始化
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
AlibcTradeSDK.asyncInit(this, new AlibcTradeInitCallback() {
@Override
public void onSuccess() {
// 初始化成功,设置相关的全局配置参数
LogUtil.e("MyApp", "阿里百川初始化成功");
}
@Override
public void onFailure(int code, String msg) {
// 初始化失败,可以根据code和msg判断失败原因,详情参见错误说明
LogUtil.e("MyApp", "阿里百川初始化失败---" + code + "---" + msg);
}
});
}
}