Android NDK - ffmpeg header files not found by compiler - android

I am trying to use the ffmpeg libraries with Android NDK in the experimental plugin.
I am attempting to compile this example:
https://github.com/roman10/android-ffmpeg-tutorial/blob/master/android-ffmpeg-tutorial01/jni/tutorial01.c
My problem is that the header files are not being found by the compiler:
Error:(13, 32) libavcodec/avcodec.h: No such file or directory
I added flags to build.grade:
cppFlags += "-ilibavcodec -ilibavutil -ilibavformat -ilibswscale"
ldFlags += "-llibavcodec -llibavutil -llibavformat -llibswscale"
Which seems to keep lint happy, but not the compiler. (Not sure if I have done this right?)
I Have added the header files to the /jni folder:
And build.grade looks like this:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "roman10.tutorial.android_ffmpeg_tutorial01"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 23
}
}
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.ndk {
moduleName = "tutorial01"
ldLibs += ["android","log","jnigraphics","z"]
cppFlags += "-ilibavcodec -ilibavutil -ilibavformat -ilibswscale"
ldFlags += "-llibavcodec -llibavutil -llibavformat -llibswscale"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.0.1'
}
Thanks.

Related

buildToolsVersion is not specified, all "apply plugin: xxxx " is in app/build.gradle

my module build.gradle
apply plugin: 'com.android.application'
model {
android {
// 编译SDK的版本
compileSdkVersion = 23
// build tools的版本
buildToolsVersion = "23.0.3"
//useLibrary = 'org.apache.http.legacy'
defaultConfig.with {
// 应用的包名
applicationId = "com.example.administrator.design"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
tasks.withType(JavaCompile) {
//指定编译JDK版本
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
}
android.ndk {
moduleName = "test"
ldLibs += "log"
abiFilters += "armeabi"
abiFilters += "armeabi-v7a"
abiFilters += "x86"
}
android.productFlavors {
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
}
android.buildTypes {
release {
// 是否进行混淆
minifyEnabled = false
// 混淆文件的位置
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles += file('proguard-android.txt')
proguardFiles += file('proguard-rules.pro')
//resValue "string", "facebook_app_id", '"597651723652854"'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//testCompile 'junit:junit:4.12'
compile 'org.xutils:xutils:3.3.20'
...
}
my project build.gradle
buildscript {
repositories {
jcenter()
//mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle wrapper
#Mon Mar 28 16:31:26 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
if I use "com.android.tools.build:gradle:0.20" in project build.gradle, and make some according changes it just works fine, But I want the new feature instant, run I have googled almost one afternoon.
Looks like you used an experimental gradle plugin version. The stable version 2.0.0 and the experimental version have some differences regarding the notation in the build.gradle file.
For example the android block needs to be outside the model block. And some attribute specifications are slightly different. Have a look at the Experimental Gradle Plugin User Guide, especially the red highlighted parts in the build.gradle example file.
Also I'm not really sure, but the non-experimental version still doesn't have full NDK support. Although it looks like the experimental version 0.6 does support the NDK as well as Instant Run, so you might use the version 0.6 instead of 2.0.

gradle dsl method not found: ' armv7a'

my build.grandle code is this one:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.assus.appweather"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName = "odroid_weather"
abiFilter "x86"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDirs 'main/src/libs'
}
}
productFlavors{
x86 {
ndk {
abiFilter "x86"
}
armv7a{
ndk {
abiFilter "armeabi-v7a"
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
}
and when I build my project, always this error is shown :
gradle dsl method not found: ' armv7a'
Gradle sync failed: Gradle DSL method not found: 'armv7a()'
Consult IDE log for more details (Help | Show Log)
some one can help me please !
Perhaps you meant to have a productFlavors that looks like this instead (it looks like you missing a closing brace):
productFlavors{
x86 {
ndk {
abiFilter "x86"
}
}
armv7a {
ndk {
abiFilter "armeabi-v7a"
}
}
}

Gradle DSL method not found: 'applicationId()'

I am getting this error on building the application in Android Studio.
Gradle DSL method not found: 'applicationId()'
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
applicationId "com.ms.knowursensor.android"
minSdkVersion 13
defaultConfig {
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "sensorgraph"
stl "c++_static"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
debuggable = true
}
}
debug {
debuggable true
jniDebuggable true
}
}
sourceSets {
main {
jniLibs.srcDir 'src/main/jniLibs'
// use the jni .so compiled from the manual ndk-build command
jni.srcDirs = [] //disable automatic ndk-build
}
}
}
repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
This issue came when i recently update the SDK. How to resolve this issue?
Move applicationId and minSdkVersion into your defaultConfig closure.

how to import android experimental module

i have experimental(v:0.4.0) android module that use gradle file with model block like this :
apply plugin: 'com.android.mode.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "21.1.2"
defaultConfig.with {
applicationId = "com.example.native_libs"
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 21
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
}
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
/*
* native build settings
*/
android.ndk {
moduleName = "native_libs"
stl = "stlport_static"
cppFlags.add("-fexceptions")
cppFlags.add("-fno-rtti")
cppFlags.add("-std=gnu++11")
ldLibs.add("z")
/*
* Other ndk flags configurable here are
* cppFlags.add("-fno-rtti")
* cppFlags.add("-fno-exceptions")
* ldLibs.addAll(["android", "log"])
* stl = "system"
*/
}
android.buildTypes {
debug {
ndk.with {
debuggable = true
}
}
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}}
and now like another module, we can't import java wrapper classes in this module that use experimental plugin.
i change apply plugin: 'com.android.mode.application' to apply plugin: 'com.android.mode.library' but nothing changed and still can't recognize java wrapper classes in native_libs module :(
how to config gradle for native module library?
why experimental plugin don't let to import module, like normal way for other modules?
[edit]
i read this doc
http://tools.android.com/tech-docs/new-build-system/gradle-experimental
but there is not way to import modules that combine native(c/c++) and java.
i find a project in github that done what i want to do :)
https://github.com/frogermcs/FlatBuffs

Android experimental grade plugin won't see my library module

I'm compiling an Android library (.aar) as a module that contains some native code and requires some libraries. Here's the build.gradle:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
//
// NOTE: change the application ID to match the play console linked application.
//
applicationId = "org.anima.mrubybridge"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 18
}
}
android.ndk {
moduleName = "mrubybridge"
CFlags += "-I/home/dragos/Downloads/mruby-1.1.0/include"
CFlags += "-I/home/dragos/Downloads/mruby-1.1.0/include"
ldLibs += ["mruby"]
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create ("arm7") {
ndk.abiFilters += "armeabi-v7a"
ndk.ldFlags += "-L/home/dragos/Downloads/mruby-1.1.0/build/armeabi-v7a/lib"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
This compiles everything (I checked the .class and .so files), but the .aar archives are almost empty with no classes or dynamic libraries. (about 2.3KB)
In the second module, I add this as a dependency:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
//
// NOTE: change the application ID to match the play console linked application.
//
applicationId = "com.example.dragos.mrubytest"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 18
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
}
dependencies {
compile project(':mrubybridge')
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
But when I try to add the Java classes from the other module, I get: Error:(12, 29) error: package org.anima.mrubybridge does not exist, most probably because they're not in the .aar.
I've added the module as a dependency (compile project(':mrubybridge')), but it doesn't really help.
I encountered the same issue. This answer solved it for me:
#Radix
"Put the .aar file in the app libs directory (create it if needed), then, add the following code in your app build.gradle":
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
repositories{
flatDir{
dirs 'libs'
}
}
Adding local .aar files to Gradle build using "flatDirs" is not working

Categories

Resources