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

1、新建项目,不选include support c++

报错:Error:Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a>
<a href="syncProject">Re-download dependencies and sync project (requires network)</a>

解决办法:将gradle/wraper/gradle-wrapper.properties文件中的

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip改为

distributionUrl=http\://services.gradle.org/distributions/gradle-2.14.1-all.zip即将s去掉。

2、在main中新建文件夹cpp,将.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://*.com/questions/26966843/java-util-zip-zipexception-duplicate-entry-during-packagealldebugclassesformult

http://wl9739.github.io/2016/09/21/%E5%9C%A8-Android-Studio-2-2-%E4%B8%AD%E6%84%89%E5%BF%AB%E5%9C%B0%E4%BD%BF%E7%94%A8-C-C-md/?utm_source=tuicool&utm_medium=referral

https://blog.csdn.net/youngpan1101/article/details/53614588

https://blog.csdn.net/huil0925/article/details/51586462

上一篇:elasticSearch6源码分析(10)SettingsModule


下一篇:java中时间类型的问题