NDK r12b and compiling source project with shared libs of FFMPEg.

254 views
Skip to first unread message

Trinity Infoman

unread,
Jul 18, 2016, 2:11:10 PM7/18/16
to android-ndk
Hello, I'm trying to compile android-app, using Android Studio ndk, embedding shared compiled "ffmpeg".

I compiled arm(android) part of ffmpeg using msys2 under Windows.
But i686 (for windows) part of ffmpeg make doesn't proceed. So i decided take already compiled libraries (shared) from
https://ffmpeg.zeranoe.com/builds/ - i don't know is it legit?
But problem that compilation (especially ld.exe) process stops on these windows libraries..
Here is what my conf are:

I have following app gradle.build:
buildscript {
    repositories
{
        jcenter
()
       
//mavenCentral()
    }
    dependencies
{
        classpath
'com.android.tools.build:gradle-experimental:0.7.2'

    }
}
apply
plugin: 'com.android.model.application'

model{
    repositories
{
        libs
(PrebuiltLibraries) {
            avcodec
{
                headers
.srcDir "src/main/jniLibs/include"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavcodec${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".dll"}")
               
}
           
}
            avformat
                   
{
                        headers
.srcDir "src/main/jniLibs/include"
                        binaries.withType(SharedLibraryBinary) {
                            sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavformat${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".dll"}")
                       
}
                   
}
            avutil
{
                headers
.srcDir "src/main/jniLibs/include"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavutil${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".dll"}")
               
}
           
}
            avdevice
{
                headers
.srcDir "src/main/jniLibs/include"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavdevice${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".dll"}")
               
}
           
}
       
}
   
}
    android
{
       
//useLibrary 'org.apache.http.legacy'
        compileSdkVersion = 17
        buildToolsVersion = '23.0.3'

        defaultConfig {
            applicationId
"WebSocketExampleClient"
            minSdkVersion.apiLevel 17
            targetSdkVersion.apiLevel 24
            versionCode 4
            versionName "1.0.1"
        }
       
/*buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }*/

        ndk {
           
// LOCAL_MODULE
            moduleName "ffmp"
            //toolchain = "gcc"
            //toolchainVersion "4.9"
            platformVersion 17
            //stl = "system"

            stl 'gnustl_shared'
            //'stlport_shared'
            // LOCAL_CPPFLAGS
            cppFlags.addAll([
                   
"-std=gnu++11",
                   
"-fexceptions",
                   
"-Wunused-function"
            ])

           
// LOCAL_LDLIBS
            ldLibs.addAll([
                   
"log",
                   
"android",
                   
"GLESv2"
                    //"ffmpeg"
            ])


         
/*   abiFilters.addAll([
                    "armeabi-v7a",
                    "arm64-v8a",
                    "x86",
                    "x86_64"
            ])*/
        }
        sources
{
           
main {
                jni
{
                    dependencies
{
                        library
"avcodec" linkage "shared"
                        library "avformat" linkage "shared"
                        library "avutil" linkage "shared"
                        library "avdevice" linkage "shared"
                    }
               
}
               
/*jniLibs {
                    source {
                        srcDir "src/main/jniLibs"
                    }
                }*/
            }
       
}
   
}

}



dependencies
{
    compile fileTree
(dir: 'libs', include: ['*.jar'])
    testCompile
'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'

}

(As you see "compileSdkVersion = 17" it means Kitkat, of Course i compiled for same target in Msys2 (mingw32))

And following error: (see under my suspicios comment)

The most intriguing part is : "C:\Users\Sergey\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\arm-linux-androideabi\bin\ld.exe"
Is it correct that Android Studio tries compile WIN-i686 architecture's code with arm-linux-androideabi-4.9\ toolchain, and btw, I don't know how to change it, (if it case).///
So here is error

C:\Users\Sergey\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\arm-linux-androideabi\bin\ld.exe
C:\Users\Sergey\AppData\Local\Android\Sdk\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64\arm-linux-androideabi\bin\ld.exe
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavcodec.dll:1:3: invalid character
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavcodec.dll:1:3: syntax error, unexpected $end
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavcodec.dll: not an object or archive
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavformat.dll:1:3: invalid character
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavformat.dll:1:3: syntax error, unexpected $end
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavformat.dll: not an object or archive
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavutil.dll:1:3: invalid character
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavutil.dll:1:3: syntax error, unexpected $end
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavutil.dll: not an object or archive
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavdevice.dll:1:3: invalid character
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavdevice.dll:1:3: syntax error, unexpected $end
Error:error: C:\Downloads\Sergey\MyApplication\app\src\main\jniLibs\armeabi\lib\libavdevice.dll: not an object or archive

(all files dll - shared libs from 'zeranoe' site, i don't know if they are causing errors?) 
I am developing under Windows.
Plz, help. any links will be appreciated (but i google'd already a lot - for ld.exe no similar errors). Thanks in advance... And sorry for newbie question, I'm in android for some week.

Dan Albert

unread,
Jul 18, 2016, 2:13:16 PM7/18/16
to android-ndk
I'm not sure if you're trying to run Windows binaries on Android, or if you're trying to use the NDK to build Windows binaries, but neither is supported. If you want to use ffmpeg on Android, you need to build it with the NDK.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/5dff2336-17eb-4efb-8d69-fb2b727d792e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Trinity Infoman

unread,
Jul 18, 2016, 2:24:41 PM7/18/16
to android-ndk
I'm trying to build Android app from Windows. And Android Studio 2.1.2 every time when I run app tries to find .dll libs of ffmpeg library. So I thought it is needed to supply windows binaries as well.
Sorry again for newbie question. 

Dan Albert

unread,
Jul 18, 2016, 2:39:10 PM7/18/16
to android-ndk
That's... interesting. Not sure why Studio would be trying to do that. You might want to try upgrading to Studio 2.2 (still a preview release, but quite stable and due to release very soon aiui). I think you also need the experimental gradle plugin? I'm not a studio user myself, so I'm not sure which pieces are expected to work with the NDK.

If those suggestions don't work, you should file a bug: http://tools.android.com/filing-bugs

Trinity Infoman

unread,
Jul 18, 2016, 2:44:25 PM7/18/16
to android-ndk
To be precise, ld.exe want's for "armeabi" build some libs, but .so files compiled under mingw - don't suit it. I am also not very familar with compiling c library. Sorry,
and thanks for any possible solutions.

Trinity Infoman

unread,
Jul 18, 2016, 2:46:56 PM7/18/16
to android-ndk
Yes, I'm using experimental-gradle plugin 0.7.2.
Other for some strange reasons don't put together with all my config.
Ok, i will try update AS. Thanks, will see if it will help

Trinity Infoman

unread,
Jul 18, 2016, 3:25:53 PM7/18/16
to android-ndk
After some intuitive thought, I replicated armeabi-v7a to armeabi and also after one run created folder mips (don't know - what is it and for what purpose?)
and copied there all libs .so from armeabi-v7a.
Now, with some additional edits in build.gradle it works and even build apk. Thanks for all efforts!
Here, my final version build.gradle, for some situations.
buildscript {
    repositories
{
        jcenter
()
       
//mavenCentral()
    }
    dependencies
{
        classpath
'com.android.tools.build:gradle-experimental:0.7.2'

    }
}
apply
plugin: 'com.android.model.application'

model{
    repositories
{
        libs
(PrebuiltLibraries) {
            avcodec
{
                headers
.srcDir "src/main/jniLibs/include"
                binaries.withType(SharedLibraryBinary) {

                    sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavcodec${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".so"}")
               
}
           
}
            avformat
                   
{
                        headers
.srcDir "src/main/jniLibs/include"
                        binaries.withType(SharedLibraryBinary) {
                            sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavformat${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".so"}")
                       
}
                   
}
            avutil
{
                headers
.srcDir "src/main/jniLibs/include"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavutil${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".so"}")
               
}
           
}
            avdevice
{
                headers
.srcDir "src/main/jniLibs/include"
                binaries.withType(SharedLibraryBinary) {
                    sharedLibraryFile
= file("src/main/jniLibs/${targetPlatform.getName()}/lib/libavdevice${targetPlatform.getName().equalsIgnoreCase("armeabi-v7a")?".so":".so"}")

               
}
           
}
       
}
   
}
    android
{
       
//useLibrary 'org.apache.http.legacy'
        compileSdkVersion = 17
        buildToolsVersion = '23.0.3'

        defaultConfig {

            applicationId
"com.example.sergey.myapplication"



            abiFilters
.addAll([
                   
"armeabi-v7a",
                       
"arm64-v8a",
           
/*           "x86",
                       "x86_64"*/
               ])

       
}
        sources
{
           
main {
                jni
{
                    dependencies
{
                        library
"avcodec" linkage "shared"
                        library "avformat" linkage "shared"
                        library "avutil" linkage "shared"
                        library "avdevice" linkage "shared"
                    }
               
}
               
/*jniLibs {
                    source {
                        srcDir "src/main/jniLibs"
                    }
                }*/
            }
       
}
   
}

}



dependencies
{
    compile fileTree
(dir: 'libs', include: ['*.jar'])
    testCompile
'junit:junit:4.12'
   // compile 'com.android.support:appcompat-v7:24.0.0'

}
Reply all
Reply to author
Forward
0 new messages