uniapp原生插件开发问题汇总

uniapp原生插件开发与使用
问题1: 导入UniPlugin-Hello-AS工程项目后,运行时虚拟器报device support x86 but apk only supports armeabi-v7a

image.png

原因: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.png

双击运行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文件:


获取插件module的aar文件.png

备注:官网原生插件开发文档中添加依赖库是所有都用compileOnly,也不知道为什么到导致运行assembleRelease时报错,将compileOnly再改为implementation即可。


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342