androidstudio中用ndk编译的问题

发布于 2022-09-04 03:13:12 字数 3389 浏览 18 评论 0

我在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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文