整理Zxing遇到的问题

发布于:2022-12-25 ⋅ 阅读:(634) ⋅ 点赞:(0)

整理二维码开源Z性项目时时候

环境 1 :

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: C:\maven
Java version: 1.8.0_341, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_341\jre 
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Apache Ant(TM) version 1.10.12 compiled on October 13 2021

 源码下载:https://github.com/zxing/zxing

zxing官网说明:https://github.com/zxing/zxing/wiki/Getting-Started-Developing(最好看看)

在windows的命令窗口:

配置Android_HOME,Ant_home,Maven_HOme(全大写),要不执行命令会找不到jar包;

编译Zxing的核心Core包,直接在主目录下mvn install 就完成了。

为了想使用他们扫码程序,编译android模块时候出现下面错误:


[ERRR] Failed to execute goal on project android-core: Could not resolve dependencies for project com.google.zxing:android-core:jar:3.5.0: Could not find artifact com.google.android:android:jar:22 at specified path D:\android20\android-sdk_r24.4.1-windows\android-sdk-windows\platforms\android-22\android.jar -> [Help 1]O
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

 告诉我是没有找到android-22 SDK 的jar包, 我的机器

 没有22版本,难道我还要下载个低版本??

回头想想Maven结构,在主项目下有个默认全局文件pom.xml,每个模块下也有,查了一下,模块下面的文件没有去找sdk的语句。再看全局的pom.xml文件,其中

<profiles>

   <profile>
      <id>android-release</id>
      <build> 
          .......
                <option>-libraryjars</option>
                <option>${android.home}/platforms/android-${android.platform}/android.jar</option>
            .......
      </build>
    </profile>

</profiles>

${android.platform} 是定义的变量,查一查这个变量的值是什么??

就在本文件里查找到了:

<properties>

  .......
    <java.version>1.8</java.version>
    <android.home>${env.ANDROID_HOME}</android.home>
    <proguard.plugin.version>2.5.3</proguard.plugin.version>
    <!-- This can't reference project.version as some subprojects version differently -->
    <zxing.version>3.5.0</zxing.version>
    <!--改为你自己系统上有的android版-->
    <android.platform>28</android.platform>

  </properties>

回到andriod目录下mvn install 就出来了,当然这是没有签名的,签名的命令如下:

mvn -Pandroid-release -Djarsigner.storepass=... -Djarsigner.keypass=... clean package android:apk

上粗体ANDROID_HOME必须在环境里定义,当然你也可以直接写你的绝对路径。

安装部署到手机上:

android/

  1. Build android/
  2. Connect your device via USB
  3. If you already have the standard version of Barcode Scanner installed, uninstall it
  4. Make sure your device is set to allow apps from untrusted sources
  5. Run mvn android:deploy.

本文含有隐藏内容,请 开通VIP 后查看