uniapp原生插件开发与使用
问题1
: 导入UniPlugin-Hello-AS工程项目后,运行时虚拟器报device support x86 but apk only supports armeabi-v7a
原因:build.gradle没集成x86模式
解决:在工程下 “app” Module的build.gradle文件中对应位置添加如下代码:
android {
defaultConfig {
//选择要添加的对应cpu类型的.so库,包括'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a','mips', 'mips64'等
ndk {
abiFilters 'x86','armeabi-v7a' //使用uniapp时必须同时选两者或者选其一
}
}
}
问题2
:打包uni-app插件时,选择Gradle--->插件module--->Tasks--->build--->assembleRelease(双击运行生成module的aar文件)
双击运行assembleRelease时失败:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':myscancode:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
Output: error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.osmium.myscancode:style/Theme.AppCompat.Light.DarkActionBar) not found.
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\merged\release\values\values.xml:83: error: style attribute 'attr/colorPrimary (aka com.osmium.myscancode:attr/colorPrimary)' not found.
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\merged\release\values\values.xml:84: error: style attribute 'attr/colorPrimaryDark (aka com.osmium.myscancode:attr/colorPrimaryDark)' not found.
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\merged\release\values\values.xml:85: error: style attribute 'attr/colorAccent (aka com.osmium.myscancode:attr/colorAccent)' not found.
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\merged\release\values\values.xml:86: error: style attribute 'attr/windowNoTitle (aka com.osmium.myscancode:attr/windowNoTitle)' not found.
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\merged\release\values\values.xml:87: error: style attribute 'attr/windowActionBar (aka com.osmium.myscancode:attr/windowActionBar)' not found.
error: failed linking references.
Command: C:\Users\liy\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\7f730b0cdc67a917825e2b83e68c7d62\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
E:\sdk\platforms\android-28\android.jar\
--manifest\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\aapt_friendly_merged_manifests\release\processReleaseManifest\aapt\AndroidManifest.xml\
-o\
C:\Users\liy\AppData\Local\Temp\aapt-2487609981588923152-out\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\drawable_btn_back_normal.png.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\drawable_btn_back_pressed.png.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\drawable_btn_back_selector.xml.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\drawable_btn_none.png.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\drawable_flash_off.png.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\drawable_flash_on.png.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\layout_my_capture_activity.xml.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\layout_toolbar_capture.xml.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\layout_top_title_back_bar.xml.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\layout_zxing_barcode_scanner.xml.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\layout_zxing_capture.xml.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\raw_zxing_beep.ogg.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-ar_values-ar.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-bg_values-bg.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-ca_values-ca.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-cs_values-cs.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-da_values-da.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-de_values-de.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-el_values-el.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-es_values-es.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-eu_values-eu.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-fi_values-fi.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-fr_values-fr.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-he_values-he.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-hi_values-hi.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-hu_values-hu.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-id_values-id.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-it_values-it.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-iw_values-iw.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-ja_values-ja.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-ko_values-ko.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-nl_values-nl.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-pl_values-pl.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-pt_values-pt.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-ro_values-ro.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-ru_values-ru.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-sk_values-sk.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-sl_values-sl.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-sv_values-sv.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-th_values-th.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-tr_values-tr.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-uk_values-uk.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-zh-rCN_values-zh-rCN.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-zh-rHK_values-zh-rHK.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values-zh-rTW_values-zh-rTW.arsc.flat\
-R\
G:\liy\projects\android\Android-SDK@1.9.9.68191_20190819-1\UniPlugin-Hello-AS\myscancode\build\intermediates\res\compiled\release\values_values.arsc.flat\
--auto-add-overlay\
--non-final-ids\
-0\
apk\
--no-version-vectors
Daemon: AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
修改插件module的gradle:除了对sdk的arr包引入不用改为implementation,其他地方的compileOnly都需改为implementation。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly fileTree(dir: '../app/libs', include: ['dc_weexsdk-release.aar', 'uniapp-release.aar'])
// 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'
implementation "com.android.support:recyclerview-v7:28.0.0"
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.alibaba.android:bindingx-core:1.0.3'
implementation 'com.alibaba.android:bindingx_weex_plugin:1.0.3'
// implementation "com.google.zxing:core:3.3.3"
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
compileOnly 'com.alibaba:fastjson:1.2.59'
}
成功:
14:32:40: Executing task 'assembleRelease'...
Executing tasks: [assembleRelease]
:myscancode:preBuild UP-TO-DATE
:myscancode:preReleaseBuild UP-TO-DATE
:myscancode:compileReleaseAidl NO-SOURCE
:myscancode:compileReleaseRenderscript UP-TO-DATE
:myscancode:checkReleaseManifest UP-TO-DATE
:myscancode:generateReleaseBuildConfig UP-TO-DATE
:myscancode:generateReleaseResValues UP-TO-DATE
:myscancode:generateReleaseResources UP-TO-DATE
:myscancode:packageReleaseResources UP-TO-DATE
:myscancode:processReleaseManifest UP-TO-DATE
:myscancode:generateReleaseRFile
:myscancode:prepareLintJar UP-TO-DATE
:myscancode:generateReleaseSources
:myscancode:javaPreCompileRelease
:myscancode:compileReleaseJavaWithJavac
:myscancode:extractReleaseAnnotations
:myscancode:mergeReleaseConsumerProguardFiles UP-TO-DATE
:myscancode:mergeReleaseShaders UP-TO-DATE
:myscancode:compileReleaseShaders UP-TO-DATE
:myscancode:generateReleaseAssets UP-TO-DATE
:myscancode:packageReleaseAssets UP-TO-DATE
:myscancode:packageReleaseRenderscript NO-SOURCE
:myscancode:processReleaseJavaRes NO-SOURCE
:myscancode:transformResourcesWithMergeJavaResForRelease
:myscancode:transformClassesAndResourcesWithSyncLibJarsForRelease
:myscancode:compileReleaseNdk NO-SOURCE
:myscancode:mergeReleaseJniLibFolders UP-TO-DATE
:myscancode:transformNativeLibsWithMergeJniLibsForRelease UP-TO-DATE
:myscancode:transformNativeLibsWithSyncJniLibsForRelease UP-TO-DATE
:myscancode:bundleReleaseAar
:myscancode:compileReleaseSources
:myscancode:mergeReleaseResources
:myscancode:verifyReleaseResources
:myscancode:assembleRelease
BUILD SUCCESSFUL in 5s
23 actionable tasks: 9 executed, 14 up-to-date
14:32:45: Task execution finished 'assembleRelease'.
成功获取插件module的aar文件:
备注:官网原生插件开发文档中添加依赖库是所有都用compileOnly,也不知道为什么到导致运行assembleRelease时报错,将compileOnly再改为implementation即可。