android中调用c++文件并转为so

时人不识凌云木,直待凌云始道高。这篇文章主要讲述android中调用c++文件并转为so相关的知识,希望能为你提供帮助。
【android中调用c++文件并转为so】1、新建项目,不选include support c++
2、新建文件夹cpp,将.cpp文件放入其中;
3、编写jni接口文件,注意文件内函数名称前缀要与app下的build.gradle的applicationId保持一致;
4、编写CMakeLists.txt,在view-> tool windows-> gradle-> build生成.so文件
编译时遇到的错误
(1)Error:Execution failed for task ‘:app:transformClassesWithDexForDebug‘.

> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.7.0_67\bin\java.exe‘‘ finished with non-zero exit value 1
        解决办法:在app下的builder.gradle 下添加 defaultConfig {
        .....        
        multiDexEnabled true
        .....
          }
  (2)Execution failed for task ‘:excelSior:packageAllDebugClassesForMultiDex‘. > java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class
    解决办法:在app下的build.gradle下添加:
    android{ configurations { all*.exclude group: ‘com.android.support‘, module: ‘support-v4‘ all*.exclude group: ‘com.android.support‘, module: ‘support-annotations‘ } }
  参考:https://stackoverflow.com/questions/26966843/java-util-zip-zipexception-duplicate-entry-during-packagealldebugclassesformult






    推荐阅读