腾讯云直播SDKCrash 相关问题_音视频解决方案_同尘科技
1. 启动屏幕分享出现如下 crash?
Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
解决方案:
在使用 SDK,将 targetSdkVersion 设置为 30,进行屏幕分享时会出现如下崩溃,这主要是因为谷歌隐私策略导致的,需要启动一个前台的 Service,并且android:foregroundServiceType="mediaProjection"
才可以解决,具体步骤如下:1. 创建一个 Service ,并绑定一个 Notification 使其作为前台 Service。
public class TestService extends Service {
private final static String NOTIFICATION_CHANNEL_ID = "com.tencent.liteav.demo.TestService"; private final static String NOTIFICATION_CHANNEL_NAME = "com.tencent.liteav.demo.channel_name"; private final static String NOTIFICATION_CHANNEL_DESC = "com.tencent.liteav.demo.channel_desc";
@Override public void onCreate() { super.onCreate(); startNotification(); }
@Override public IBinder onBind(Intent intent) { throw new UnsupportedOperationException("Not yet implemented"); }
private void startNotification() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return; }
Intent notificationIntent = new Intent(this, TestService.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID).setLargeIcon( BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground)) .setSmallIcon(R.drawable.ic_launcher_foreground) .setContentTitle("Starting Service") .setContentText("Starting monitoring service") .setContentIntent(pendingIntent); Notification notification = notificationBuilder.build(); NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(NOTIFICATION_CHANNEL_DESC); NotificationManager notificationManager = (NotificationManager)getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); //必须使用此方法显示通知,不能使用notificationManager.notify,否则还是会报上面的错误 startForeground(1, notification); }}
2. 在 AndroidManifest.xml 中配置:2.1 加入权限
2.2 注册 Service
3. 在启动推流前,请先启动此 Service:
startService(new Intent(this, TestService.class));
注意:9.0 及之后的系统,应用退后台后 摄像头和麦克风将停止工作,该 Service 也可保证应用退后台摄像头和麦克风依旧可以正常工作。
2. 应用启动出现如下 crash?
java.lang.UnsatisfiedLinkError: No implementation found for byte[] com.tencent.liteav.basic.license.LicenceCheck.nativeIvParameterSpec(byte[]) (tried Java_com_tencent_liteav_basic_license_LicenceCheck_nativeIvParameterSpec and Java_com_tencent_liteav_basic_license_LicenceCheck_nativeIvParameterSpec___3B);
java.lang.UnsatisfiedLinkError: No implementation found for boolean com.tencent.liteav.sdk.common.LicenseChecker.nativeSetLicense
java.lang.UnsatisfiedLinkError: No implementation found for void com.tencent.liteav.basic.log.TXCLog.nativeLogInit()
java.lang.UnsatisfiedLinkError: No implementation found for void com.tencent.liteav.base.util.LiteavLog.nativeSetConsoleLogEnabled(boolean)
出现 java.lang.UnsatisfiedLinkError 异常,一般是 so 加载失败了。
解决方案:
Android Studio 编译错误可能和 Android Studio 编译有关,so 没有正确编译到 APK 内,此时 Clean Build,然后重新编译即可。设备 CPU 架构和打包到 APK 内的 so 架构不匹配请检查设备 CPU 架构和打包到 APK 内部的 so 是否匹配,如果不匹配,请在 build.gradle 中正确配置:
defaultConfig { ndk { abiFilters 'armeabi-v7a', 'arm64-v8a' }}
对音视频的解决方案有疑惑?想了解解决方案收费? 联系解决方案专家
腾讯云限时活动1折起,即将结束: 马上收藏
同尘科技为腾讯云授权服务中心,购买腾讯云享受折上折,更有现金返利:同意关联,立享优惠
阿里云解决方案也看看?: 点击对比阿里云的解决方案
暂无评论,你要说点什么吗?