androidstudio中用ndk编译的问题

我在Ubuntu上将已编译好的ffmpeg放入我的androidstudio工程,配置OK后,为什么他提示

Error:(319, 10) fatal error: 'libavcodec/avcodec.h' file not found

而同样的我在cmd里,进入到项止jni目录,用ndk-build直接编译就不会出现这个问题,求大神指点

这是我gradle的代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.zyt.vm.lp"
        minSdkVersion 10
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            jniDebuggable true
        }
    }
    sourceSets.main {
        jni.srcDirs = [] // This prevents the auto generation of Android.mk
        jniLibs.srcDir 'src/main/libs' // This is not necessary unless you have precompiled libraries in your project.
        //jniLibs.srcDirs = ['src/main/libs','src/main/jniLibs']
    }

    externalNativeBuild{
        ndkBuild{
            path file('src\\main\\jni\\Android.mk')
        }
    }

    task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=1',
                'NDK_LOG=1'
    }


    task cleanNative(type: Exec, description: 'Clean JNI object files') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build.cmd",
                '-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
                'clean'
    }

    clean.dependsOn 'cleanNative'

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.0'
    testCompile 'junit:junit:4.12'
}

########################################################################################################################################################
#    LivePublisher Complie
########################################################################################################################################################
include $(CLEAR_VARS)
LOCAL_MODULE    := LivePublisher
LOCAL_SRC_FILES := LivePublisher.c
#LOCAL_C_INCLUDES := \
#$(FFInclude)

LOCAL_LDLIBS:=-llog -lz -lm -landroid
LOCAL_SHARED_LIBRARIES := avformat avutil avcodec avfilter postproc swresample swscale
#LOCAL_CFLAGS:= "-I$(FF)/ffmpeg/include"
include $(BUILD_SHARED_LIBRARY)

编译好的几个库大体都是这样写的

#libavformat
include $(CLEAR_VARS)
LOCAL_MODULE := avformat
LOCAL_SRC_FILES := $(FF)/libavformat.so
LOCAL_EXPORT_C_INCLUDES := $(FFInclude)
include $(PREBUILT_SHARED_LIBRARY)
阅读 5.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题