Skip to content

Commit

Permalink
minSdkVersion 19. Multidex and desugaring.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkistner committed Oct 25, 2021
1 parent cc34502 commit 9beeac7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ repositories {
dependencies {
implementation 'com.journeyapps:zxing-android-embedded:4.2.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
}
android {
Expand All @@ -39,7 +38,12 @@ android {

## Older SDK versions

For Android SDK versions < 24, you can downgrade `zxing:core` to 3.3.0 or earlier for Android 14+ support:
By default, only SDK 24+ is supported, even though the library specifies 19 as the minimum version.
No guarantees are made on support for SDK versions below 24 - you'll have to test to make sure it's compatible.

For versions 19 - 23, one of two changes are required:

### Option 1. Downgrade zxing:core to 3.3.0

```groovy
repositories {
Expand All @@ -48,22 +52,43 @@ repositories {
dependencies {
implementation('com.journeyapps:zxing-android-embedded:4.2.0') { transitive = false }
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.zxing:core:3.3.0'
}
android {
buildToolsVersion '28.0.3'
}
```
You'll also need this in your Android manifest:

```xml
<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
```
### Option 2: Desugaring

No guarantees are made on support for older SDK versions - you'll have to test to make sure it's compatible.
This option does not require changing library versions, but may complicate the build process.

See [Java 8+ API desugaring support](https://developer.android.com/studio/write/java8-support#library-desugaring).

```groovy
android {
defaultConfig {
// Important: multidex must be enabled
// https://developer.android.com/studio/build/multidex#mdex-gradle
multiDexEnabled true
minSdkVersion 19
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation "androidx.multidex:multidex:2.0.1"
}
```

## Hardware Acceleration

Expand Down
15 changes: 10 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ android {
compileSdkVersion project.androidTargetSdk

defaultConfig {
minSdkVersion 24
multiDexEnabled true
minSdkVersion 19
targetSdkVersion project.androidTargetSdk
versionCode 411
versionName "4.1.1"
Expand Down Expand Up @@ -51,6 +52,7 @@ android {
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand All @@ -62,13 +64,16 @@ dependencies {
// implementation 'com.journeyapps:zxing-android-embedded:<version>'
implementation project(':zxing-android-embedded')

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation "androidx.legacy:legacy-support-v13:1.0.0"

// Desugaring and multidex is required for API < 21.
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation "androidx.multidex:multidex:2.0.1"

// leakcanary is for development purposes only
// https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

// AboutLibraries
implementation "com.mikepenz:aboutlibraries:6.2.3"
Expand Down
7 changes: 2 additions & 5 deletions sample/src/main/java/example/zxing/SampleApplication.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package example.zxing;

import android.app.Application;

import com.squareup.leakcanary.LeakCanary;
import androidx.multidex.MultiDexApplication;

/**
*
*/
public class SampleApplication extends Application {
public class SampleApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
LeakCanary.install(this);
}
}

0 comments on commit 9beeac7

Please sign in to comment.