Android Vlc for Android 低版本运行与最新版本运行至AndroidStudio ...

打印 上一主题 下一主题

主题 871|帖子 871|积分 2613

低版本项目来自
https://github.com/shihyu/vlc-android/tree/master
高版本使用vlc官方即可
https://github.com/videolan/vlc-android
高版本编译过程未更新完成,待更新 1228
1 低版本

最终效果如图

可直接运行在as的版本 已上传至github https://github.com/yyoujinga/vlc-android/tree/master
提示:低版本和现在的相比,缺失很多功能(如倍速播放),但假如仅用来做视频播放器,还是很合适的,已经支持多格式。
本文章重要记录了报错和办理方案
重要修改的地方为项目级build.gradle和两个模块的build.gralde,gradle插件和gradle版本,因为是十几年前的项目,我最终可正常运行的版本如图所示

1 预备工作

旧版本没有gradle文件夹,从本地已有的项目中拷贝一个过去即可(假如不想测试可运行的最终版本,可参考我上面的版本)

2

   The “android” command is no longer included in the SDK. Any references to it (e.g. by third-party plugins) should be removed.
com.android.build.gradle.internal.crash.ExternalApiUsageException: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.android.builder.core.DefaultManifestParser()
Cannot invoke method include() on null object
  修改项目级build.gradle
  1. // Top-level build file where you can add configuration options common to all sub-projects/modules.
  2. buildscript {
  3.     repositories {
  4.         maven { url 'https://maven.aliyun.com/repository/public/' }
  5.         maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
  6.         maven { url 'https://maven.aliyun.com/repository/central' }
  7.         google()
  8.         jcenter()
  9.     }
  10.     dependencies {
  11.         classpath 'com.android.tools.build:gradle:3.1.0'
  12.         classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
  13.     }
  14. }
  15. allprojects {
  16.     repositories {
  17.         maven { url 'https://maven.aliyun.com/repository/public/' }
  18.         maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
  19.         maven { url 'https://maven.aliyun.com/repository/central' }
  20.         google()
  21.         jcenter()
  22.     }
  23. //    apply plugin: 'android-sdk-manager'
  24. }
  25. ext {
  26.     buildToolsVersion = "22"
  27.     compileSdkVersion = 22
  28. }
复制代码

参考
https://stackoverflow.com/questions/42720255/errorthe-android-command-is-no-longer-included-in-the-sdk-any-references-to
3

Could not find matching constructor for: com.android.builder.core.DefaultManifestParser()
DefaultManifestParser 在较新的 Gradle 插件版本中被移除了,该版本我记得是2.2的gradle,相对有点太低了,移除该方法即可,因为是要对播放器进行定制,以是原获取版本的方法也不太需要,我这边都注释掉了。
模块libvlc目录下的build.gradle(模块vlc-android目录下同理,下面会直接po代码)
libvlc
  1. import com.sun.corba.se.impl.orbutil.concurrent.Sync
  2. apply plugin: 'com.android.library'
  3. android {
  4.     compileSdkVersion rootProject.ext.compileSdkVersion
  5.     buildToolsVersion rootProject.ext.buildToolsVersion
  6.     sourceSets {
  7.     main {
  8.         jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
  9.         jniLibs.srcDir 'jni/libs' // Where generated .so files are placed.
  10.         manifest.srcFile 'AndroidManifest.xml'
  11.         java.srcDirs = ['src']
  12.         resources.srcDirs = ['src']
  13.         aidl.srcDirs = ['src']
  14.         renderscript.srcDirs = ['src']
  15.         res.srcDirs = ['res']
  16.         assets.srcDirs = ['assets']
  17.     }
  18.     }
  19.     defaultConfig {
  20.         minSdkVersion 7
  21.         targetSdkVersion 22
  22.     }
  23.     buildTypes {
  24.         release {
  25.             minifyEnabled false
  26.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
  27.         }
  28.     }
  29.     // Make per-variant version code
  30.     libraryVariants.all { variant ->
  31. //        def manifestParser = new com.android.builder.core.DefaultManifestParser()
  32.         // get the version code of each flavor
  33. //        def vlcVersion = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
  34.         //Custom APK name
  35. //        def vlcVersion = 'c'+variant.getVersionCode()
  36.         def vlcVersion = 'c'+ 2.2
  37. //        variant.outputs.each { output ->
  38. //            def outputFile = output.outputFile
  39. //            if (outputFile != null && outputFile.name.endsWith('.aar')) {
  40. //                def fileName = "libvlc-${vlcVersion}.aar"
  41. //                output.outputFile = new File(outputFile.parent, fileName)
  42. //            }
  43. //        }
  44.         variant.outputs.all { output ->
  45.             def outputFileName = "your-custom-output-file-name.apk"
  46.             output.outputFileName = outputFileName
  47.         }
  48.     }
  49. }
  50. /*
  51. * Include GDB files into apk
  52. */
  53. //afterEvaluate {
  54. //    Sync packageTask = project.getTasks().findByName("packageReleaseJniLibs")
  55. //    packageTask.include(['**/gdbserver', '**/gdb.setup'])
  56. //}
  57. afterEvaluate {
  58.     Sync packageTask = project.getTasks().findByName("packageReleaseJniLibs")
  59.     if (packageTask != null) {
  60.         packageTask.include(['**/gdbserver', '**/gdb.setup'])
  61.     } else {
  62.         println("Task 'packageReleaseJniLibs' not found. Skipping include configuration.")
  63.     }
  64. }
  65. class BuildNative extends Exec {
  66. }
  67. tasks.withType(BuildNative){
  68.     /*
  69.     Properties set for Android Studio own shell.
  70.     when you run gradlew from cli, OS shell env variables will be used
  71.     To be able to build from Android Studio, you have to set ndk.dir & sdk.dir
  72.     properties in local.properties in the root folder, like this (for example):
  73.     sdk.dir=/home/<username>/SDK/android-sdk-linux
  74.     ndk.dir=/home/<username>/SDK/android-ndk-r10b
  75.      */
  76.     if (System.getenv('ANDROID_SDK') == null || System.getenv('ANDROID_NDK') == null) {
  77.         Properties properties = new Properties()
  78.         properties.load(project.rootProject.file('local.properties').newDataInputStream())
  79.         environment 'ANDROID_NDK', properties.getProperty('ndk.dir')
  80.         environment 'ANDROID_SDK', properties.getProperty('sdk.dir')
  81.     }
  82.     workingDir '..'
  83. //    commandLine './compile-libvlc.sh'
  84. }
  85. //task buildDebugARMv5(type:BuildNative) {
  86. //    args('-a', "armeabi-v5")
  87. //}
  88. task buildDebugARMv6(type:BuildNative) {
  89.     args('-a', "armeabi")
  90. }
  91. task buildDebugARMv6_nofpu(type:BuildNative) {
  92.     args('-a', "armeabi-nofpu")
  93. }
  94. task buildDebugARMv7(type:BuildNative) {
  95.     args('-a', "armeabi-v7a")
  96. }
  97. task buildDebugARM64(type:BuildNative) {
  98.     args('-a', "arm64-v8a")
  99. }
  100. task buildDebugx86(type:BuildNative) {
  101.     args('-a', "x86")
  102. }
  103. task buildDebugx86_64(type:BuildNative) {
  104.     args('-a', "x86_64")
  105. }
  106. task buildDebugMIPS(type:BuildNative) {
  107.     args('-a', "mips")
  108. }
  109. task buildDebugMIPS64(type:BuildNative) {
  110.     args('-a', "mips64")
  111. }
  112. dependencies {
  113.     compile 'com.android.support:support-annotations:22.2.0'
  114. }
复制代码

模块vlc-android 目录下
  1. apply plugin: 'com.android.application'
  2. android {
  3.     compileSdkVersion rootProject.ext.compileSdkVersion
  4.     buildToolsVersion rootProject.ext.buildToolsVersion
  5.     flavorDimensions "target", "abi"
  6.     lintOptions {
  7.         abortOnError false
  8.         disable 'MissingTranslation', 'ExtraTranslation'
  9.     }
  10.     defaultConfig {
  11.         applicationId "org.videolan.vlc"
  12.         resValue "string", "build_time", buildTime()
  13.         resValue "string", "build_host", hostName()
  14.         resValue "string", "build_revision", revision()
  15.         //Set the build ABI according to build types only if not launched from compile.sh
  16.         if (System.getenv('PASSWORD_KEYSTORE') == null)
  17.             tasks.whenTaskAdded { task ->
  18.                 if (task.name.startsWith('assemble')) {
  19.                     /*if (task.name.endsWith('ARMv5Debug'))
  20.                         task.dependsOn(":libvlc:buildDebugARMv5")
  21.                     else */if (task.name.endsWith('ARMv6fpuDebug'))
  22.                         task.dependsOn(":libvlc:buildDebugARMv6")
  23.                     else if (task.name.endsWith('ARMv6nofpuDebug'))
  24.                         task.dependsOn(":libvlc:buildDebugARMv6_nofpu")
  25.                     else if (task.name.endsWith('ARMv7Debug'))
  26.                         task.dependsOn(":libvlc:buildDebugARMv7")
  27.                     else if (task.name.endsWith('ARMv8Debug'))
  28.                         task.dependsOn(":libvlc:buildDebugARM64")
  29.                     else if (task.name.endsWith('X86Debug'))
  30.                         task.dependsOn(":libvlc:buildDebugx86")
  31.                     else if (task.name.endsWith('X86_64Debug'))
  32.                         task.dependsOn(":libvlc:buildDebugx86_64")
  33.                     else if (task.name.endsWith('MIPSDebug'))
  34.                         task.dependsOn(":libvlc:buildDebugMIPS")
  35.                     else if (task.name.endsWith('MIPS64Debug'))
  36.                         task.dependsOn(":libvlc:buildDebugMIPS64")
  37.                 }
  38.             }
  39.     }
  40.     signingConfigs {
  41.         release {
  42.             /*
  43.             To set this properties, create file gradle.properties with these 3 props.
  44.             e.g.
  45.             keyStoreFile=/home/<username>/.android/debug.keystore
  46.             storealias=androiddebugkey
  47.             storepwd=android
  48.              */
  49.             storeFile file(keyStoreFile)
  50.             keyAlias storealias
  51.             if (System.getenv('PASSWORD_KEYSTORE') != null && !System.getenv('PASSWORD_KEYSTORE').isEmpty()){
  52.                 storePassword = System.getenv('PASSWORD_KEYSTORE')
  53.                 keyPassword = System.getenv('PASSWORD_KEYSTORE')
  54.             } else {
  55.                 storePassword storepwd
  56.                 keyPassword storepwd
  57.             }
  58.         }
  59.     }
  60.     buildTypes {
  61.         release {
  62.             signingConfig signingConfigs.release
  63.             minifyEnabled true
  64.             shrinkResources false
  65.             proguardFile 'proguard.cfg'
  66.         }
  67.         debug {
  68.             applicationIdSuffix ".debug"
  69.             jniDebuggable true
  70.         }
  71.     }
  72.     productFlavors {
  73.         vanilla {
  74.             dimension "target"
  75.             versionCode = 0
  76.             buildConfigField "boolean", "tv", "false"
  77.         }
  78.         tv {
  79.             minSdkVersion 17
  80.             dimension "target"
  81.             versionCode = 1
  82.             buildConfigField "boolean", "tv", "true"
  83.         }
  84.         chrome {
  85.             minSdkVersion 19
  86.             dimension "target"
  87.             versionCode = 2
  88.             buildConfigField "boolean", "tv", "false"
  89.         }
  90.         ARMv5 {
  91.             dimension "abi"
  92.             versionCode = 1
  93.         }
  94.         ARMv6nofpu {
  95.             dimension "abi"
  96.             versionCode = 2
  97.         }
  98.         ARMv6fpu {
  99.             dimension "abi"
  100.             versionCode = 3
  101.         }
  102.         ARMv7 {
  103.             dimension "abi"
  104.             versionCode = 4
  105.         }
  106.         x86 {
  107.             dimension "abi"
  108.             versionCode = 5
  109.         }
  110.         MIPS {
  111.             dimension "abi"
  112.             versionCode = 6
  113.         }
  114.         ARMv8 {
  115.             dimension "abi"
  116.             versionCode = 7
  117.         }
  118.         x86_64 {
  119.             dimension "abi"
  120.             versionCode = 8
  121.         }
  122.         MIPS64 {
  123.             dimension "abi"
  124.             versionCode = 9
  125.         }
  126.     }
  127.     // make per-variant version code
  128.     applicationVariants.all { variant ->
  129. //        def manifestParser = new com.android.builder.core.DefaultManifestParser()
  130. //        // get the version code of each flavor
  131. //        def vlcVersion = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
  132. //        def targetVersion = variant.productFlavors.get(0).versionCode
  133. //        def abiVersion = variant.productFlavors.get(1).versionCode
  134. //
  135. //        // set the composite code
  136. //        variant.mergedFlavor.versionCode = targetVersion * 10000000 + manifestParser.getVersionCode(android.sourceSets.main.manifest.srcFile) + abiVersion
  137. //        variant.mergedFlavor.versionName = vlcVersion
  138.         def versionName = 'v'+ variant.getVersionName()
  139.         def vlcVersion = 'c'+variant.getVersionCode()
  140.         //Custom APK name
  141. //        variant.outputs.each { output ->
  142. //            def outputName = "VLC-Android-"
  143. //            if (!variant.productFlavors.get(0).name.equals("vanilla"))
  144. //                outputName += variant.productFlavors.get(0).name.toUpperCase()+"-"
  145. //            outputName += vlcVersion+"-"+variant.productFlavors.get(1).name+".apk"
  146. //            output.outputFile = new File(output.outputFile.parentFile, outputName);
  147. //        }
  148.         variant.outputs.each { output ->
  149.             def outputName = "VLC-Android-"
  150.             if (!variant.productFlavors.get(0).name.equals("vanilla"))
  151.                 outputName += variant.productFlavors.get(0).name.toUpperCase() + "-"
  152.             outputName += vlcVersion + "-" + variant.productFlavors.get(1).name + ".apk"
  153.             output.outputFileName = outputName // 使用 outputFileName 替代 outputFile
  154.         }
  155.     }
  156.     sourceSets.main {
  157.         manifest.srcFile 'AndroidManifest.xml'
  158.         java.srcDirs = ['src']
  159.         resources.srcDirs = ['src']
  160.         aidl.srcDirs = ['src']
  161.         renderscript.srcDirs = ['src']
  162.         res.srcDirs = ['res']
  163.         assets.srcDirs = ['assets']
  164.     }
  165.     sourceSets.test {
  166.         java.srcDirs = ['test']
  167.     }
  168.     sourceSets.tv {
  169.         manifest.srcFile 'tv/AndroidManifest.xml'
  170.         java.srcDirs = ['tv/src']
  171.         resources.srcDirs = ['tv/src']
  172.         aidl.srcDirs = ['tv/src']
  173.         renderscript.srcDirs = ['tv/src']
  174.         res.srcDirs = ['tv/res']
  175.         assets.srcDirs = ['tv/assets']
  176.     }
  177.     sourceSets.chrome {
  178.         manifest.srcFile 'chrome/AndroidManifest.xml'
  179.     }
  180. }
  181. dependencies {
  182.     compile project(':libvlc')
  183.     compile 'com.android.support:appcompat-v7:22.2.0'
  184.     compile 'com.android.support:cardview-v7:22.2.0'
  185.     compile 'com.android.support:recyclerview-v7:22.2.0'
  186.     compile 'com.android.support:design:22.2.0'
  187.     compile 'com.android.support:support-annotations:22.2.0'
  188.     tvCompile 'com.android.support:leanback-v17:22.2.0'
  189.     testCompile 'junit:junit:4.12'
  190. }
  191. def buildTime() {
  192.     return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
  193. }
  194. def hostName() {
  195.     return System.getProperty("user.name") + "@" + InetAddress.localHost.hostName
  196. }
  197. def revision() {
  198.     def code = new ByteArrayOutputStream()
  199. //    exec {
  200. //        commandLine 'git', 'rev-parse', '--short', 'HEAD'
  201. //        standardOutput = code
  202. //    }
  203.     return code.toString()
  204. }
复制代码

4

Cannot set the value of read-only property ‘outputFile’ for object of type com.android.build.gradle.internal.api.LibraryVariantOutputImpl.
缘故原由:
outputFile 属性在 Gradle 3.x 或更高版本中被标记为 只读。
假如项目代码中实验直接修改 outputFile,例如在 build.gradle 文件中有类似如下代码:
output.outputFile = …
就会触发该错误。
办理: 具体buildgradle文档上面已经给出,这里不再重复
output.outputFileName = outputName // 使用 outputFileName 替代 outputFile

5

Build file ‘E:\oproject\vlc-video\vlc-android-master\libvlc\build.gradle’ line: 65
A problem occurred configuring project ‘:libvlc’.
   Cannot invoke method include() on null objectafterEvaluate {
Sync packageTask = project.getTasks().findByName(“packageReleaseJniLibs”)
packageTask.include([‘/gdbserver’, '/gdb.setup’])
}
  class BuildNative extends Exec {
}
办理:
代码实验访问 packageTask 时,没有精确找到任务,导致 packageTask 为 null。
直接写个判断,假如为null就不进行该操纵了(目前我没有用到该方法,假如有用到的请再斟酌一下)
  1. afterEvaluate {
  2.     Sync packageTask = project.getTasks().findByName("packageReleaseJniLibs")
  3.     if (packageTask != null) {
  4.         packageTask.include(['**/gdbserver', '**/gdb.setup'])
  5.     } else {
  6.         println("Task 'packageReleaseJniLibs' not found. Skipping include configuration.")
  7.     }
  8. }
复制代码
6

A problem occurred evaluating project ‘:vlc-android’.
   Process ‘command ‘git’’ finished with non-zero exit value 128def revision() {
def code = new ByteArrayOutputStream()
exec {
commandLine ‘git’, ‘rev-parse’, ‘–short’, ‘HEAD’
standardOutput = code
}
return code.toString()
}
  办理
我没有用gitclone,直接下载下来到本地解压运行的,这里注释掉即可。

7

libvlc模块中注册清单中 爆红
办理
我直接注释掉了,但很奇怪另一个模块同样的代码没有报错

到这里 设置问题基本已经办理了,接下来是小问题
8

vlc-video\vlc-android-master\vlc-android\src\org\videolan\vlc\gui\video\VideoPlayerActivity.java:381: ����: �Ҳ�������
mSysTime = (TextView) findViewById(R.id.player_overlay_systime);
^
����: ���� player_overlay_systime
�: �� id mSysTime = (TextView) findViewById(R.id.player_overlay_systime);
办理
layout文件中有两个activity_videoplayer,两个文件都确保添加player_overlay_systime即可
到这里即可正常运行了,整体项目代码已放在文章开头
2 高版本


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

知者何南

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表