1、声网jar + 下载so开发 1
This commit is contained in:
parent
32257ce5a0
commit
f5d8b7fed1
@ -257,12 +257,12 @@ android {
|
||||
println("处理ndk 版本 = " + tskReqStr)
|
||||
def isLink = tskReqStr.contains("Link")
|
||||
if (isLink) {//移除32位so库可以有效降低包体大小,等需要时再弄
|
||||
// abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||
abiFilters "arm64-v8a", "x86_64"
|
||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||
// abiFilters "arm64-v8a", "x86_64"
|
||||
println("打包ndk 链接")
|
||||
} else {
|
||||
// abiFilters "armeabi-v7a", "arm64-v8a"
|
||||
abiFilters "arm64-v8a"
|
||||
abiFilters "armeabi-v7a", "arm64-v8a"
|
||||
// abiFilters "arm64-v8a"
|
||||
println("打包ndk其他")
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
package com.shayu.phonelive.activity;
|
||||
|
||||
|
||||
import static com.yunbao.live.views.SystemMessageViewHolder.PERMISSION_REQUEST_CODE;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
@ -12,19 +17,26 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.ActivityOptionsCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@ -68,9 +80,15 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import myname.pdlive.shayu.R;
|
||||
|
||||
@ -145,15 +163,215 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL
|
||||
}
|
||||
}
|
||||
};
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000);
|
||||
try {
|
||||
LogUtil.uploadErrorLog(AppContext.sInstance);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SpUtil.getInstance().setBooleanValue("NOTIFICATION", NotificationManagerCompat.from(this).areNotificationsEnabled());
|
||||
|
||||
if(CommonAppConfig.IS_GOOGLE_PLAY != 0){
|
||||
//渠道包
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000);
|
||||
}else {
|
||||
//链接包 下载so库
|
||||
String permission1 = Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
String permission2 = Manifest.permission.WRITE_EXTERNAL_STORAGE;
|
||||
|
||||
int isPermission1 = ContextCompat.checkSelfPermission(mContext, permission1);
|
||||
int isPermission2 = ContextCompat.checkSelfPermission(mContext, permission2);
|
||||
if (isPermission1 == PackageManager.PERMISSION_GRANTED && isPermission2 == PackageManager.PERMISSION_GRANTED) {
|
||||
downLoadSo();
|
||||
} else {
|
||||
//申请权限
|
||||
ActivityCompat.requestPermissions(LauncherActivity.this, new String[]{permission1,
|
||||
permission2}, PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == PERMISSION_REQUEST_CODE) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
|
||||
downLoadSo();
|
||||
Log.e("downLoad", "outputDir:>>>" + grantResults[0]);
|
||||
Log.e("downLoad", "grantResults[0]:>>>" + grantResults[1]);
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
|
||||
Toast.makeText(this, "需要您的手機存儲權限!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void downLoadSo() {
|
||||
//存储路径 //检查是否下载过
|
||||
File outputDir = new File(getApplicationInfo().dataDir, Constants.DOWNLOAD_SO);
|
||||
|
||||
if (!outputDir.exists()) {
|
||||
Log.e("downLoad", "outputDir:>>>" + outputDir.exists());
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
File fileSo = new File(outputDir, "soKuZip.zip");
|
||||
|
||||
|
||||
//解压后的文件数量必须要有22个
|
||||
//如果文件存在,解压后 文件数量一致,直接进入下一步
|
||||
if (fileSo.exists() && getFileCount(outputDir.getAbsolutePath()) == 23){
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
//如果沒下載,需要清楚之前的登錄信息,這樣用戶就有時間去下載so庫 ,
|
||||
//根據手機cup 架構類型去下載支持不同類型的so 庫
|
||||
String cpuAbi = "";
|
||||
cpuAbi = Build.CPU_ABI;
|
||||
Log.i("download", cpuAbi);
|
||||
//2开始下载
|
||||
//检查压缩包是否已经下载过
|
||||
|
||||
Log.i("download", "permission WRITE_EXTERNAL_STORAGE.." + ContextCompat.checkSelfPermission(LauncherActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE));
|
||||
Log.i("download", "permission READ_EXTERNAL_STORAGE .." + ContextCompat.checkSelfPermission(LauncherActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE));
|
||||
String soUrl = String.format("https://downs.yaoulive.com/%s.zip", cpuAbi);
|
||||
Log.i("download", soUrl);
|
||||
|
||||
if (!fileSo.exists()) {
|
||||
downloadSo(outputDir.getAbsolutePath(), soUrl);
|
||||
}else if (fileSo.exists() && getFileCount(outputDir.getAbsolutePath()) < 23) {
|
||||
fileSo.delete();
|
||||
downloadSo(outputDir.getAbsolutePath(), soUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Dialog progressDialog;
|
||||
public ProgressBar progressBar;
|
||||
public TextView tvProgress;
|
||||
|
||||
private void showDialog(Activity context) {
|
||||
progressDialog = new Dialog(context, com.yunbao.common.R.style.dialog);
|
||||
View view = LayoutInflater.from(context).inflate(com.yunbao.common.R.layout.dialog_progress, null);
|
||||
tvProgress = view.findViewById(com.yunbao.common.R.id.tvProgress);
|
||||
TextView tvDialogTitle = view.findViewById(com.yunbao.common.R.id.tvDialogTitle);
|
||||
tvDialogTitle.setText("首次安装,请等待");
|
||||
progressBar = view.findViewById(com.yunbao.common.R.id.progressBar);
|
||||
progressDialog.setContentView(view);
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = wm.getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
Window window = progressDialog.getWindow();// 这部分是设置dialog宽高的,宽高是我从sharedpreferences里面获取到的。之前程序启动的时候有获取
|
||||
window.getDecorView().setPadding(0, 0, 0, 0);
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
lp.width = width / 4 * 3;
|
||||
window.setAttributes(lp);
|
||||
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
}
|
||||
public void downloadSo(String outputDir, String downloadUrl) {
|
||||
DownloadUtil downloadUtil = new DownloadUtil();
|
||||
showDialog(LauncherActivity.this);
|
||||
downloadUtil.download("so", outputDir, "soKuZip.zip", downloadUrl, new DownloadUtil.Callback() {
|
||||
@Override
|
||||
public void onSuccess(File file) {
|
||||
progressDialog.dismiss();
|
||||
//存储路径
|
||||
// File outputDir = new File(getApplicationInfo().dataDir, "dataLib");
|
||||
//
|
||||
// if (!outputDir.exists()) {
|
||||
// Log.e("downLoad", "outputDir:>>>" + outputDir.exists());
|
||||
// outputDir.mkdirs();
|
||||
// }
|
||||
mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 20);
|
||||
File fileSo = new File(outputDir, "soKuZip.zip");
|
||||
try {
|
||||
unzip(fileSo.getAbsolutePath(), outputDir);
|
||||
} catch (Exception e) {
|
||||
Log.e("ZipCheck", "Error reading ZIP file", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int progress) {
|
||||
progressBar.setProgress(progress);
|
||||
Log.i("downLoad", "progress:>>>" + progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
//资源下载失败
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压 .zip 文件到目标目录
|
||||
*/
|
||||
public void unzip(String zipFilePath, String destDirectory) throws IOException {
|
||||
File destDir = new File(destDirectory);
|
||||
if (!destDir.exists()) {
|
||||
destDir.mkdirs();
|
||||
}
|
||||
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
|
||||
ZipEntry entry = zipIn.getNextEntry();
|
||||
while (entry != null) {
|
||||
|
||||
String filePath = destDirectory + File.separator + sanitizePath(entry.getName());
|
||||
Log.d("Unzip", "Extracting: " + filePath);
|
||||
if (!entry.isDirectory()) {
|
||||
extractFile(zipIn, filePath);
|
||||
} else {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
zipIn.closeEntry();
|
||||
entry = zipIn.getNextEntry();
|
||||
}
|
||||
zipIn.close();
|
||||
}
|
||||
|
||||
private String sanitizePath(String path) {
|
||||
return path.replaceAll("[^a-zA-Z0-9./_-]", "_");
|
||||
}
|
||||
|
||||
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
|
||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
|
||||
byte[] bytesIn = new byte[4096];
|
||||
int read = 0;
|
||||
while ((read = zipIn.read(bytesIn)) != -1) {
|
||||
bos.write(bytesIn, 0, read);
|
||||
}
|
||||
bos.close();
|
||||
}
|
||||
|
||||
public int getFileCount(String directoryPath) {
|
||||
File directory = new File(directoryPath);
|
||||
if (!directory.exists() || !directory.isDirectory()) {
|
||||
// 目录不存在或不是目录
|
||||
return -1;
|
||||
}
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null) {
|
||||
// 无法列出目录内容
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fileCount = 0;
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
fileCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return fileCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片倒计时
|
||||
|
@ -315,4 +315,7 @@ public class Constants {
|
||||
public static boolean isShowLiveDialog = false;//是否在直播间打开单聊
|
||||
public static int firstInto = 0;//
|
||||
|
||||
// 声网so
|
||||
public static final String DOWNLOAD_SO = "agora-lib";
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
@ -51,8 +50,6 @@ dependencies {
|
||||
println('链接包,使用本地声网Jar + 下载SO')
|
||||
api files('../libs/agora-rtc-sdk.jar')
|
||||
}
|
||||
api files('../libs/agora-rtc-sdk.jar')
|
||||
|
||||
api project(path: ':FaceUnity')
|
||||
api project(path: ':common')
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import com.yunbao.common.utils.L;
|
||||
import com.yunbao.common.utils.StringUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import io.agora.rtc2.ChannelMediaOptions;
|
||||
@ -113,6 +114,13 @@ public class SWAuManager extends BaseCacheManager {
|
||||
config.mContext = mContext;
|
||||
config.mAppId = CommonAppConfig.getSwAppId();
|
||||
config.mEventHandler = mRtcEventHandler;
|
||||
|
||||
if(CommonAppConfig.IS_GOOGLE_PLAY == 0){
|
||||
//链接包,声网加载下载的 So文件
|
||||
File file = new File(mContext.getApplicationInfo().dataDir, com.yunbao.common.Constants.DOWNLOAD_SO);
|
||||
config.mNativeLibPath = file.getAbsolutePath();
|
||||
}
|
||||
|
||||
// 创建并初始化 RtcEngine
|
||||
mRtcEngine = (RtcEngineEx) RtcEngineEx.create(config);
|
||||
} catch (Exception e) {
|
||||
|
BIN
libs/agora-rtc-sdk.jar
Normal file
BIN
libs/agora-rtc-sdk.jar
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user