很简单
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.example.myapplication" minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "" abiFilters 'arm64-v8a', 'armeabi-v7a' } } } externalNativeBuild { cmake { path "src/main/java/com/example/myapplication/jni/CMakeLists.txt" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
CMakeList他自己就有
具体可以看https://blog.csdn.net/qq_36523667/article/details/80093935
生成so是成功了
但是网上都是使用的老的库的api,新的库的api还没人写过,这个我能写,不过很费时间;
还有就是对ndk了解的没有那么深,他内置的cmakelists我不知道怎么把我的c函数打包进so里去,这个我也能做,不过也很费时间。
等以后闲的蛋疼了再搞吧!现在先用Compressor库顶一下。
看到他这样的api
.setMaxWidth(640).setMaxHeight(480)这两个数值越高,压缩力度越小,图片也不清晰,
.setQuality(75)这个方法只是设置图片质量,并不影响压缩图片的大小KB
.setCompressFormat(Bitmap.CompressFormat.WEBP) WEBP图片格式是Google推出的 压缩强,质量高,但是IOS不识别,需要把图片转为字节流然后转PNG格式
.setCompressFormat(Bitmap.CompressFormat.PNG)PNG格式的压缩,会导致图片变大,并耗过大的内存,手机反应缓慢
.setCompressFormat(Bitmap.CompressFormat.JPEG)JPEG压缩;压缩速度比PNG快,质量一般,基本上属于1/10的压缩比例
我就决定再也不捡起来手上这个坑了。哈哈。Compressor都替我们做好了