diff --git a/android/build.gradle b/android/build.gradle index aca8e7f4..1dba5bd5 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -4,23 +4,30 @@ version '0.11.0' apply plugin: 'com.android.library' android { - compileSdkVersion 30 + compileSdkVersion 31 + namespace "com.befovy.fijkplayer" defaultConfig { minSdkVersion 16 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + targetSdkVersion 31 // 关键:与 compileSdkVersion 保持一致,避免版本脱节 + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" // 替换为 AndroidX 测试 runner } + lintOptions { disable 'InvalidPackage' } -} + // 强制统一资源编译版本,避免冲突 + resourcePrefix "fijkplayer_" // 可选:给插件资源加前缀,防止与项目资源重名 +} dependencies { - - // implementation(name: 'fijkplayer-full-release', ext: 'aar') - - // fijkplayer-full include the java lib and native shared libs for armv5 armv7 arm64 x86 x86_64 - implementation 'com.befovy.fijkplayer:fijkplayer-full:0.7.16' - implementation 'androidx.annotation:annotation:1.2.0' + // 核心依赖:锁定低版本 core-ktx,避免传递引入 lStar 相关资源 + implementation 'androidx.core:core-ktx:1.6.0' + // 升级 annotation 依赖,确保与 AndroidX 版本兼容 + implementation 'androidx.annotation:annotation:1.5.0' + // 保留原 fijkplayer-full 依赖,添加强制排除冲突的 AndroidX 库 + implementation('com.befovy.fijkplayer:fijkplayer-full:0.7.16') { + exclude group: 'androidx.core' // 排除库自带的 core 依赖,使用上面锁定的 1.6.0 版本 + } } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 27920a61..c4e83de3 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ - + diff --git a/android/src/main/java/com/befovy/fijkplayer/FijkPlugin.java b/android/src/main/java/com/befovy/fijkplayer/FijkPlugin.java index fdff7ea0..80b3fa49 100644 --- a/android/src/main/java/com/befovy/fijkplayer/FijkPlugin.java +++ b/android/src/main/java/com/befovy/fijkplayer/FijkPlugin.java @@ -6,8 +6,7 @@ //of this software and associated documentation files (the "Software"), to deal //in the Software without restriction, including without limitation the rights //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -//copies of the Software, and to permit persons to whom the Software is -//furnished to do so, subject to the following conditions: +//copies of the Software, subject to the following conditions: // //The above copyright notice and this permission notice shall be included in all //copies or substantial portions of the Software. @@ -52,16 +51,13 @@ import io.flutter.plugin.common.EventChannel; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.view.TextureRegistry; import tv.danmaku.ijk.media.player.IjkMediaPlayer; /** * FijkPlugin */ -public class FijkPlugin implements MethodCallHandler, FlutterPlugin, ActivityAware, FijkEngine, FijkVolume.VolumeKeyListener, AudioManager.OnAudioFocusChangeListener { +public class FijkPlugin implements MethodChannel.MethodCallHandler, FlutterPlugin, ActivityAware, FijkEngine, FijkVolume.VolumeKeyListener, AudioManager.OnAudioFocusChangeListener { // show system volume changed UI if no playable player // hide system volume changed UI if some players are in playable state @@ -81,7 +77,6 @@ public class FijkPlugin implements MethodCallHandler, FlutterPlugin, ActivityAwa private WeakReference mActivity; private WeakReference mContext; - private Registrar mRegistrar; private FlutterPluginBinding mBinding; // Count of playable players @@ -97,21 +92,6 @@ public class FijkPlugin implements MethodCallHandler, FlutterPlugin, ActivityAwa private boolean mAudioFocusRequested = false; - /** - * Plugin registration. - */ - @SuppressWarnings("unused") - public static void registerWith(Registrar registrar) { - final MethodChannel channel = new MethodChannel(registrar.messenger(), "befovy.com/fijk"); - FijkPlugin plugin = new FijkPlugin(); - plugin.initWithRegistrar(registrar); - channel.setMethodCallHandler(plugin); - - final FijkPlayer player = new FijkPlayer(plugin, true); - player.setupSurface(); - player.release(); - } - @Override public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { final MethodChannel channel = new MethodChannel(binding.getBinaryMessenger(), "befovy.com/fijk"); @@ -132,6 +112,12 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { @Override public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { mContext = null; + mBinding = null; + if (mEventChannel != null) { + mEventChannel.setStreamHandler(null); + mEventSink.setDelegate(null); + mEventChannel = null; + } } @Override @@ -167,8 +153,6 @@ public void onDetachedFromActivity() { public TextureRegistry.SurfaceTextureEntry createSurfaceEntry() { if (mBinding != null) { return mBinding.getTextureRegistry().createSurfaceTexture(); - } else if (mRegistrar != null) { - return mRegistrar.textures().createSurfaceTexture(); } return null; } @@ -178,8 +162,6 @@ public TextureRegistry.SurfaceTextureEntry createSurfaceEntry() { public BinaryMessenger messenger() { if (mBinding != null) { return mBinding.getBinaryMessenger(); - } else if (mRegistrar != null) { - return mRegistrar.messenger(); } return null; } @@ -195,9 +177,7 @@ public Context context() { @Nullable private Activity activity() { - if (mRegistrar != null) { - return mRegistrar.activity(); - } else if (mActivity != null) { + if (mActivity != null) { return mActivity.get(); } else { return null; @@ -215,23 +195,10 @@ public String lookupKeyForAsset(@NonNull String asset, @Nullable String packageN //noinspection ConstantConditions path = mBinding.getFlutterAssets().getAssetFilePathByName(asset, packageName); } - } else if (mRegistrar != null) { - if (TextUtils.isEmpty(packageName)) { - path = mRegistrar.lookupKeyForAsset(asset); - } else { - path = mRegistrar.lookupKeyForAsset(asset, packageName); - } } return path; } - - private void initWithRegistrar(@NonNull Registrar registrar) { - mRegistrar = registrar; - mContext = new WeakReference<>(registrar.activeContext()); - init(registrar.messenger()); - } - private void initWithBinding(@NonNull FlutterPluginBinding binding) { mBinding = binding; mContext = new WeakReference<>(binding.getApplicationContext()); @@ -270,7 +237,7 @@ public void onCancel(Object o) { @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { Activity activity; switch (call.method) { case "getPlatformVersion":