构建FFMPEG静态库时,Linker命令在退出代码1中失败



我正在尝试构建FFMPEG静态库,并将其链接到Android项目以实现视频播放器。目标是使播放器能够从各种来源接收视频文件,类似于P2P文件共享网络。(目标API是21级,与MediaSource的官方解决方案相距仅1级(

我设法从此仓库中编译了FFMPEG(所有使用的代码(,但后来我陷入了链接问题。每当我尝试编译时,我都会在我的代码中获取ffmpeg方法的列表,并获得一个简短的雄辩消息:

链接器命令失败,出口代码1

我不知道如何将-v标志传递给Android Studio的链接器。如果有人暗示我会很棒。

我使用Android Studio,与Gradle和Cmake一起构建。

有我的文件: build.gradle(project(

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(模块(

apply plugin: 'com.android.application'
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        productFlavors {
            x86 {
                ndk {
                    abiFilter "x86"
                }
            }
            arm {
                ndk {
                    abiFilters "armeabi-v7a"
                }
            }
            armv7 {
                ndk {
                    abiFilters "armeabi-v7a"
                }
            }
        }
        defaultConfig {
            applicationId "com.example.ledo.ndkapplication"
            minSdkVersion 22
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            externalNativeBuild {
                cmake {
                    cppFlags "-std=c++11 -frtti -fexceptions"
                    arguments '-DANDROID_PLATFORM=android-16'
                }
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
            }
        }
        splits {
            abi {
                enable true
                reset()
                include 'x86', 'armeabi-v7a'
                universalApk true
            }
        }
    }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        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.3.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.android.support:design:25.3.1'
        compile 'com.writingminds:FFmpegAndroid:0.3.2'
        testCompile 'junit:junit:4.12'
    }

cmakelists.txt

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 2.8)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
             native-lib
             # Sets the library as a shared library.
             SHARED
             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp
             src/main/cpp/NativePlayer.h
             src/main/cpp/NativePlayer.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
              log-lib
              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
find_library(png-lib png)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
#avcodec
#avfilter
#avformat
#avutil
#swresample
#swscale
#${ANDROID_ABI}
message(${ANDROID_ABI})
set(FFMPEG_ROOT_DIR src/main/libs/ffmpeg/${ANDROID_ABI})
add_library(avcodec STATIC IMPORTED)
add_library(avformat STATIC IMPORTED)
add_library(avfilter STATIC IMPORTED)
add_library(avutil STATIC IMPORTED)
add_library(swresample STATIC IMPORTED)
add_library(swscale STATIC IMPORTED)
#SET_TARGET_PROPERTIES(avcodec PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavcodec.a)
#SET_TARGET_PROPERTIES(avfilter PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avfilter PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavfilter.a)
#SET_TARGET_PROPERTIES(avformat PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavformat.a)
#SET_TARGET_PROPERTIES(avutil PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavutil.a)
#SET_TARGET_PROPERTIES(swresample PROPERTIES LINKER_LANGUAGE C)
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libswresample.a)
#SET_TARGET_PROPERTIES(swscale PROPERTIES LINKER_LANGUAGE C)
set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libswscale.a)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/include )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib )
target_link_libraries( # Specifies the target library.
                       native-lib
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}
                       avcodec
                       avformat
                       #avfilter
                       #swresample
                       #swscale
                       #avutil
                       GLESv2)

我在以下位置有.a文件:

  • %PROJECT_DIR%/app/src/libs/ffmpeg/armeabi-v7a
  • %PROJECT_DIR%/app/src/libs/ffmpeg/armeabi-v7a-neon
  • %PROJECT_DIR%/app/src/libs/ffmpeg/x86

在我看来,链接器本身会错过文件。(如果我放错了放置,我会得到不同的放置。(

错误'链接器命令在出口代码1 '中失败了,后来是更详细的错误。要查找更多详细信息,在Xcode中,单击 buildtime 下的错误,然后在日志中选择。这应该给您额外的提示。没有任何特定错误,就不可能知道问题所在。

最新更新