-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Getting Started Developing
If you just need a pre-built JAR file, you can always find compiled resources from the Maven release repository, including recent snapshot/nightly builds.
Download the latest release, or, retrieve the latest source code from Github.
The code is organized into several subdirectories, corresponding to modules, like core/ and javase/. Within each Java-based module, there is a pom.xml file for use with Apache Maven.
A few configuration steps are needed, depending on which modules you want to build. From the directory where you unpacked or checked out the source code:
The Android SDK must be installed of course. Run the tool called sdkmanager and ensure that platform support for the Android release targeted by the app is installed. At the time of this writing, that's platform level 22 / Android 5.1.
export ANDROID_HOME=/change/this/path/to/android-sdk
Note that release 3.4.0 and later requires Java 8, which requires targeting API level 24 or later. For a possible way to use it with earlier API levels, see https://github.com/zxing/zxing/wiki/Frequently-Asked-Questions#it-doesnt-work-with-java-7--no-interface-method-sortljavautilcomparator or simply use an earlier release.
From the root of the project, run mvn install to compile, test and assemble all modules. Add -DskipTests to skip unit tests. Note that Android-related modules and apps will not be built unless ANDROID_HOME is set.
Compiled .jar files are found in submodules after this. For example, the compiled core/ code is available at core/target/core-x.y.z.jar.
To build the Barcode Scanner Android app, a few slightly different steps are needed. From android/, run mvn package android:apk to produce a compile .apk file in target. Use android-x.y.z-aligned.apk.
Other users will not be able to build the signed release version, but the command is: mvn -Pandroid-release -Djarsigner.storepass=... -Djarsigner.keypass=... clean package android:apk.
Note that the deployable .war file will be produced in the target/ directory.
Most components are libraries and are not run directly.
- Build
android/ - Connect your device via USB
- If you already have the standard version of Barcode Scanner installed, uninstall it
- Make sure your device is set to allow apps from untrusted sources
- Run
mvn android:deploy.
After building, in the javase/ directory, execute mvn -DskipTests package assembly:single to create a single JAR file containing all classes needed to run client command line apps, as target/javase-x.y.z-jar-with-dependencies.jar. Run CommandLineRunner with simply:
java -jar target/javase-x.y.z-jar-with-dependencies.jar [URL | FILE]
Path syntax is different on Windows. Here and elsewhere you will need to use ';' rather than ':' to separate classpath elements, and likely need to use the '' path separator.
core/, javase/, android-integration and zxingorg can be used directly in a Maven-based project without any download or installation. Instead, add as dependencies from groupID com.google.zxing artifactIDs core, javase, android-integration or zxingorg:
<dependencies>
...
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>(the current version)</version>
</dependency>
</dependencies>
- For
android-integration,android-core,zxing.appspot.com, (andzxingorg?) manually updateparentandversionto the upcoming release - Commit locally only
- Update the current milestone in Github as needed and close it
-
unset ANDROID_HOMEso as to not release Android apps - Make sure you have a GitHub PAT available with access to the repo, as it will be your GitHub 'password' when prompted by the release process
- You will need a
private-settings.xmlfile with Sonatype repo credentials; see https://central.sonatype.org/publish/generate-portal-token/ -
mvn -P\!appspot -s private-settings.xml clean release:clean release:prepareand optionally add-DreleaseVersion=x.y.z -DdevelopmentVersion=a.b.c-SNAPSHOTif the answer is not the one Maven guesses and you want to avoid repeating the answer - If all is well,
mvn -B -P\!appspot -Darguments="-Dgpg.passphrase=..." -s private-settings.xml release:perform - Find legacy staging repo details at https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?ip=any&profile_id=com.google.zxing
- POST a request with something like this to transfer artifact:
curl -v -X POST -u "username:token" https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/(username)/(IP)/com.google.zxing--default-repository - Log in to
central.sonatype.organd finish the release. - Update the release on Github
- Restore modules
versionandparentto latest SNAPSHOT, like they were manually modified above - To immediately publish a next snapshot,
mvn -s private-settings.xml clean deploy - To get the site ready, first go back to the tag,
git checkout -f tags/zxing-x.y.z mvn clean sitemvn site:stage site:deploy -pl .git add docs- You may wish to
git statusto ensure that all the changes are indocs/and that they make sense git checkout mastergit commit -m 'Update site for x.y.z'git push origin master
After building with mvn package, deploy from target/zxing.appspot.com-x.y.z with:
gcloud app deploy --project [PROJECT] --no-promote --version [VERSION]