2

I have a problem with the compilation of ASSIMP for Android.

I use the Android NDK (and JNI) to call my C++ code in a JAVA activity.

Gradle calls my CMakelist to compile my shared library. In this CMakelist I target my .cpp files and my library subdirectory (assimp and glm). The assimp build throws an error: 'error: cannot find -lpthread'

My problem is: how can I compile ASSIMP and how can I include assimp in my Android NDK project?

petezurich
  • 9,280
  • 9
  • 43
  • 57
nicolasl
  • 21
  • 2
  • Check this, https://stackoverflow.com/questions/30801752/android-ndk-and-pthread You need to remove -lpthread from linker libraries list, since bionic have embedded pthread. – Victor Gubin Apr 05 '18 at 07:26
  • I don't link pthread. Assimp link Pthread in his Cmakelist/Makefile probably, but i never see where. So how can i modify the assimp cmake to del pthread or ignore the missing link ? – nicolasl Apr 05 '18 at 07:58
  • 2
    locate the following : `IF( WIN32 ) SET( platform_libs ) ELSE( WIN32 ) SET( platform_libs pthread ) ENDIF( WIN32 )` in assimp CmakeList and remove `SET( platform_libs pthread )` – Victor Gubin Apr 05 '18 at 08:08
  • Thank @VictorGubin it's working ! i can compile without error now. – nicolasl Apr 05 '18 at 08:32

1 Answers1

0

for my sample project I am using the following Assimp-gradle buid file and it works fine for me. One important note: disable the unittest stuff ( the option ASSIMP_BUILD_TESTS must be set to off ) because there is a bug in assimp regarding pthread support for gtest.

android {
    compileSdkVersion 24
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.app.kkulling_solutions.assimpviewer"
        minSdkVersion 21
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                arguments '-DASSIMP_BUILD_ZLIB=ON -DASSIMP_BUILD_TESTS=OFF'
                cppFlags '-fexceptions -frtti -std=c++11'
            }
        }
        //-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
                'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path 'src/main/cpp/JNI/CMakeLists.txt'
        }

    }
}

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

Let me know if you have any other questions!

KimKulling
  • 2,654
  • 1
  • 15
  • 26
  • I can compile assimp with the ndk when i disable the tests but i have a crash when i try to import a model (The same code work on a Deb9 with intel 7, geforce 1070). Maybe the memory structure of Android cause some troubles – nicolasl Apr 10 '18 at 05:50
  • Which format? Thee are some alignment bugs there I haven't fixed yet. – KimKulling Apr 10 '18 at 06:22
  • I use a *.ifc file – nicolasl Apr 11 '18 at 07:13
  • OK, I can fix the issue when you can create an issue repot for it: https://github.com/assimp/assimp/issues It would be great if you could attach a small ifc-file which creates the issue. – KimKulling Apr 11 '18 at 07:56
  • Need add "," beween multiple arguments, '-DASSIMP_BUILD_ZLIB=ON', '-DASSIMP_BUILD_TESTS=OFF', otherwise it does not work as you expect. – Jian Zhong Mar 27 '20 at 09:33