侧边栏壁纸
  • 累计撰写 416 篇文章
  • 累计创建 65 个标签
  • 累计收到 154 条评论

目 录CONTENT

文章目录

IjkPlayer SDK 源码导入到Android Studio中各种问题解决 第一篇

Z同学
2022-02-18 / 0 评论 / 3 点赞 / 1,543 阅读 / 4,995 字
温馨提示:
本文最后更新于 2022-02-21,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

介绍

从git上拉取的ijkPlayer 的源码是一个完整的Android项目,那么就应该能够导入到Android Studio之中。

而我在导入过程中碰见了不少的问题。本篇就记录一下我的导入过程中的问题以及处理吧。

最终目标是能够直接采用Android Studio 进行编译ijkPlayerSO文件吧。

1. Could not determine java version from '11.0.8'.

image-20220218165600748

出现这个问题的主要原因在于项目中使用的Gradle版本太低了。

classpath 'com.android.tools.build:gradle:2.1.3'

这个版本在你的Android Studio所支持的最低版本不兼容。需要我们升级项目中gradle版本。

解决方法

Could not determine java version from '11.0.8'.-错误解决 (zinyan.com)

我在这个文章中有介绍如何解决。

image-20220218170041784

把这个地方改为4.8.1版本就可以了。

为什么我说4.8.1 是因为错误警告中,告诉了我需要升级gradle-wrapper到4.8.1 version。 你的错误如果不是这个数,你就升级到错误日志提示的版本就可以了。

2. Could not initialize class com.android.sdklib.repositoryv2.AndroidSdkHandler

这个问题的意思就是说,当前无法初始化AndroidSdkHandler类。

我们查询详细的Build 错误日志会显示:

* What went wrong:
A problem occurred configuring project ':ijkplayer-arm64'.
> Failed to notify project evaluation listener.
   > Could not initialize class com.android.sdklib.repositoryv2.AndroidSdkHandler

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

出现这个类找不到的原因,我们首先得弄明白com.android.sdklib.repositoryv2.AndroidSdkHandler 这个类是从哪里获取的。

这个类其实是从项目目录的build.gradle文件中的classpath 'com.android.tools.build:gradle:2.1.3' 指向的 gradle库里面的类。

但是现在最新的Android Studio 不在支持3.4以下的tools工具了。所以ijkPlayer项目中配置的2.1.3版本不能导入。我们需要升级该版本才行。

解决方法

由于从老版本往上升级。我没有用最新的,就用了个3.6.4版本。

classpath "com.android.tools.build:gradle:3.6.4"

如果你的Android Studio更高,不支持3.6.4。那你可以继续修改这个版本吧。

3. Could not find com.android.tools.build:gradle:3.6.4.

我们配置完Gradle.3.6.4之后提示下载失败

image-20220218171551489

我们其他项目都可以使用3.6.4 版本。但是为什么就它不行了呢?

那是因为jcenter库的问题。

image-20220218171708380

jcenter仓库关闭了,我们需要迁移到google()mavenCentral()

解决方法

buildscript {
    repositories {
//        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.6.4"

        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

但是从googlemavenCentral 仓库下载的话。速度会受到比较大的影响,因为它们的仓库地址都在国外。

你如果下载不成功,可以试试仓库地址切换到国内阿里云的镜像地址。

切换方法可以参考我的这个文章 :Android Studio Maven 仓库切换到阿里云 (zinyan.com)

如果你下载成功,那不用切换仓库也没关系了。

4. gradle-bintray-plugin 1.7下载失败。

我们继续构建的话,会出现以下错误,Android Studio从两个地方去下载gradle-bintray-plugin 都找不到,下载失败了。

image-20220218172216212

简直一波三折啊。

这个地方很简单,我们可以删除掉这个plugin插件。因为它的作用实际就是将我们的项目编译结果上传到jcenter仓库。这个仓库都混不下去了。我们完全不需要这个插件啊。

解决方法

删除掉 gradle-bintray-plugin

buildscript {
    repositories {
//        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.6.4"
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
//        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

5. Minimum supported Gradle version is 5.6.4. Current version is 4.8.1.

我们编译的时候,会提示Gradle Version版本不对。 最低只支持5.6.4 我们在第一步中改的4.8.1版本太低。

那么为什么当初改4.8.1版本的时候不会报错?那是因为改它的时候,android.tools.build版本还是老版本的原因。

image-20220218173124594

这两个地方标注的其实是两个不同的插件。但是左边的Android Tools.build.Gradle 插件是Android官方自己基于右边的Gradle版本做的一个定制扩展版本。左边的必须依赖右边的Gradle

两者之间有一个最低版本兼容的问题。当然从2021.1版本之后这两个插件的版本号被统一了。

针对这两个的问题,我有一个文章详细介绍了:Android Studio 中的Gradle版本介绍 (zinyan.com) 可以通过这个进行了解。

解决方法

修改 gradle-wrapper.properties文件中的版本号为5.6.4

image-20220218173524690

到这一步,项目终于能够Build了。

效果图如下

image-20220218173754955

6. Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: ijkplayer-arm64, ijkplayer-armv5, ijkplayer-armv7a, ijkplayer-example, ijkplayer-exo, ijkplayer-java, ijkplayer-x86, ijkplayer-x86_64

这个信息就不是错误,主要是警告。因为在更新的Gradle版本下,compile指令已经被废弃淘汰了。

需要我们替换每个moduile里面的compile 改为api或者 implementation

解决方法

老的写法:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
   //改为
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

那么如果碰见all32Compile时候该怎么改?

all32Compile project(':ijkplayer-armv5')
all32Compile project(':ijkplayer-armv7a')
all32Compile project(':ijkplayer-x86')
 
 改为:
all32Implementation project(':ijkplayer-armv5')
all32Implementation project(':ijkplayer-armv7a')
all32Implementation project(':ijkplayer-x86')

这个all32 其实就是在上面定义的 productFlavors

它决定了每个Flavors 依赖不一样的项目而已。

全部替换完毕后,我们Build项目,就没有这个错误了。

7. The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.6.4.

警告信息:

The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.6.4.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Remove Build Tools version and sync project
Affected Modules: ijkplayer-arm64, ijkplayer-armv5, ijkplayer-armv7a, ijkplayer-example, ijkplayer-exo, ijkplayer-java, ijkplayer-x86, ijkplayer-x86_64

这个问题很简单。它的介绍内容已经讲明白了。

因为我们的 Android Gradle Plugin 插件的版本是3.6.4。它支持的最低Android SDK Build Tools 版本是28.0.3 而这个版本是 buildToolsVersion 配置的版本号。

我们修改一下 compileSdkVersionbuildToolsVersion版本号就可以了。

解决方法

在项目最外层的build.gradle文件中修改ext{} 里面标注的版本号就可以了。

image-20220218175148302

我们修改到这一步的时候,也只是能够用Android Studio 阅读代码而已。

由于篇幅有限。本篇就先到这里吧。下一篇再继续处理各种警告问题。

如果找不到,可以通过 ijkplayer (zinyan.com) 分类。查询到本站关于ijkplayer 中的全部内容。

3

评论区