切换ndk-build到gradle-build
接到一个任务
将现有的ndk-build 切换到gradle build
一开始是网上找资料 +现有项目的gradle脚本东拼西凑 能够buildsuccessful
但是出来的apk 你都不知道是哪里出错导致的
然后开始了control +c /v 大法
找现成的 gayhub 搜索gradle jni android
./gradlew build
报错Android home 没定义 添加local.properties
test@qemu05:~/zhekun/gradlebuild/Android-hello-jni_Gradle$ cat local.properties # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # location of the SDK. This is only used by Ant # For customization when using a Version Control System, please read the # header note. sdk.dir=/home/test/env/sdk #ndk.dir=/home/test/env/ndk/21.3.6528147 ndk.dir=/home/test/env/ndk/r20b
报错
A problem occurred evaluating root project 'hello-jni'.
> Failed to apply plugin [id 'android']
> Gradle version 2.10 is required. Current version is 5.4.1.
解决方法并设置环境变量 但是后来好像没解决
wget https://downloads.gradle-dn.com/distributions/gradle-2.1-all.zip
test@qemu05:~/zhekun/gradlebuild/Android-hello-jni_Gradle$ cat ~/.bashrc|grep gradle
export PATH=/home/test/zhekun/gradlebuild/gradle-2.2/bin:$PATH
然后换了一种执行方式
这年头拿来主义也不容易啊
compileSdkVersion:编译时的环境,与运行时无关。把这个设置成最高,可以避免使用被弃用的API。
minSdkVersion:app软件运行时支持的最低的Android版本。
targetSdkVersion:创建Android项目使用的API版本。使用低版本API就能实现的功能就不要用更高的API版本,因为高版本API可能导致程序的不兼容,影响app在不同安卓版本手机中的显示效果。但也要注意,高版本API会修复和完善低版本中出现的问题,提供更多更好的类和接口给开发者使用。同时高版本API也会新增一些方法和属性,以前多行代码才能搞定的事,现在可能只要一行代码就能搞定。
===========================================================
开始将公司的代码结构转移到这个helloworld
很明显AndroidManifest.xml这里的 package="com.intel.btft.androidlog"要按照jni目录结构改
/home/test/zhekun/gradlebuild/Android-hello-jni_Gradle/src/com/intel/btft/androidlog
刚刚不知道改了什么
build successful
然后还没高兴几秒钟 被我改fail了
看来定时备份很重要啊 TAT
FAILURE: Build failed with an exception.
* What went wrong:
Task 'build.gradle' not found in root project 'androidlog'.
草我服了 这两个命令到底什么区别
懂了懂了
和项目名称没关系
因为之前gradle build 写成了gradle build.gradle 导致编译失败
可以看到这个乱写的rootprojectname 变成apk的名字了
=============================================================
运行单元测试指令的时候报错
android.util.AndroidException: INSTRUMENTATION_FAILED: com.intel.btft.androidlog /android.test.InstrumentationTestRunner
at com.android.commands.am.Instrument.run(Instrument.java:519)
at com.android.commands.am.Am.runInstrument(Am.java:197)
at com.android.commands.am.Am.onRun(Am.java:80)
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: Component Info{com.intel.btft.androidlog/android.test.InstrumentationTestRunner} at com.a ndroid.internal.os.BaseCommand.run(BaseCommand.java:62)
这应该是什么库没加进去
源码搜了下
AndroidManifest.xml:23: <instrumentation android:name="android.test.Instr umentationTestRunner" android:label="sample tests" android:targetPackage=" com.intel.btft.androidlog">
原来是依赖没加
果然 没有什么是白学的 之前看的android教程这就派上用场了
完结撒花