【发布时间】:2017-11-01 09:32:08
【问题描述】:
升级到 Android Studio 3.0 后,一个项目也更新了,尽管我仍然保留了它的备份。我虽然会同意从非常早期的实验性 gradle 插件版本升级到 3.0.0 版本,但我遇到了很多麻烦。
我认为顶级 gradle 文件看起来绝对没问题。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'com.android.tools.build:gradle-experimental:0.9.3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app gradle 构建文件是我一直在对其进行大量更改的文件。它目前抱怨cppFlags 错误:
Error:(25, 0) Could not find method cppFlags() for arguments [-std=c++11, -fexceptions, -Isrc/main/android/armeabi-v7a/include, -frtti, -O2] on object of type com.android.build.gradle.internal.dsl.NdkOptions.
到目前为止,这个 gradle 文件的变化是:
//apply plugin: 'com.android.model.application'
apply plugin: 'com.android.application'
//model {
android {
buildToolsVersion "26.0.2"
compileSdkVersion 23
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
ndk {
def ffmpeg = "src/main/android/armeabi-v7a/include"
moduleName = "ffplayer3jni"
ldLibs "log", "android", "GLESv2", "dl", "EGL", "z",
"stdc++", "OpenSLES"
//cppFlags.addAll("-std=c++11", "-fexceptions", '-I'+file(ffmpeg),
// "-D __cplusplus=201103L", "-frtti",
// "-D __GXX_EXPERIMENTAL_CXX0X__", "-O2")
cppFlags "-std=c++11", "-fexceptions", "-I${ffmpeg}", "-frtti", "-O2"
stl "gnustl_static"
//abiFilters.addAll("armeabi-v7a")
abiFilters "armeabi-v7a"
}
}
}
android.buildTypes {
release {
minifyEnabled false
proguardFiles.add(file('proguard-rules.pro'))
}
}
repositories {
def loc = "src/main/jniLibs/armeabi-v7a/"
libs(PrebuiltLibraries) {
libavutil {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavutil.so")
}
}
libavcodec {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavcodec.so")
}
}
libavformat {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavformat.so")
}
}
libavfilter {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavfilter.so")
}
}
libpostproc {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libpostproc.so")
}
}
libswresample {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libswresample.so")
}
}
libswscale {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libswscale.so")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "libavformat" linkage "shared"
library "libavcodec" linkage "shared"
library "libavfilter" linkage "shared"
library "libavutil" linkage "shared"
library "libswscale" linkage "shared"
library "libswresample" linkage "shared"
library "libpostproc" linkage "shared"
}
}
}
}
//}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
原始 gradle 文件仍然适用于 Android Studio 2.3,即使它使用的是旧的实验性插件。该文件是/曾经是:
apply plugin: 'com.android.model.application'
model {
android {
def ffmpeg = "src/main/android/armeabi-v7a/include"
buildToolsVersion "25.0.3"
compileSdkVersion 25
defaultConfig.with {
minSdkVersion.apiLevel = 19
}
ndk {
moduleName = "ffplayer3jni"
ldLibs.addAll("log", "android", "GLESv2", "dl", "atomic", "EGL",
"z", "stdc++", "OpenSLES")
cppFlags.addAll("-std=c++11", "-fexceptions", '-I'+file(ffmpeg),
"-D __cplusplus=201103L", "-frtti",
"-D __GXX_EXPERIMENTAL_CXX0X__", "-O2")
CFlags.add('-I'+file(ffmpeg))
stl = "gnustl_static"
//stl = "stlport_shared"
abiFilters.addAll("armeabi-v7a")
}
}
android.buildTypes {
release {
minifyEnabled false
proguardFiles.add(file('proguard-android.txt'))
}
}
repositories {
def loc = "src/main/jniLibs/armeabi-v7a/"
libs(PrebuiltLibraries) {
libavutil {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavutil.so")
}
}
libavcodec {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavcodec.so")
}
}
libavformat {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavformat.so")
}
}
libavfilter {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libavfilter.so")
}
}
libpostproc {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libpostproc.so")
}
}
libswresample {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libswresample.so")
}
}
libswscale {
binaries.withType(SharedLibraryBinary) {
sharedLibraryFile = file(loc + "libswscale.so")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "libavformat" linkage "shared"
library "libavcodec" linkage "shared"
library "libavfilter" linkage "shared"
library "libavutil" linkage "shared"
library "libswscale" linkage "shared"
library "libswresample" linkage "shared"
library "libpostproc" linkage "shared"
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
所以我的问题是,我需要进行哪些更改才能使该项目与 Android Studio 3.0 中的新 gradle 插件一起使用?
如您所见,我进行了一些更改。移动部分并更改选项以最终通过 gradle 脚本,但现在我非常卡住。
编辑:我最终放弃了,并在 Android Studio 3.0.1 中从头开始创建了一个新项目。经过多次谷歌搜索,我设法完成了所有本机代码、ffmpeg 库和正确的构建。
【问题讨论】:
-
这只是概述了从 2.3 到新构建系统的升级。我要从 0.9.3 到 3.0.0。这么久以前不情愿是我的错。考虑创建一个新项目并复制所有内容。
标签: android gradle android-ndk