从gradle-experimental升级Gradle 3.0.0:0.9.3错误

时间:2017-11-01 09:32:08

标签: android gradle android-ndk

升级到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
}

应用程序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库和正确的构建完成。

1 个答案:

答案 0 :(得分:1)

  

我最终放弃了,并在Android Studio 3.0.1中从零开始创建了一个新项目。经过大量的谷歌搜索,我设法获得所有本机代码,ffmpeg库和正确的构建完成。

是的,实验性插件的概念非常不同。它试图引入一个新的基于groovy的构建系统。在这里,您依靠已建立的工具--cmake或Android.mk - 来构建本机库。