feat(androidX): upgrading to sdk 28 and androidx (#2068)

* upgrading to sdk 28 and androidx

* revert attempt to fix build

* fixing build

* build version fix

* updating example app

* manifest update

* using stable release, instead of beta

* androidx migration doc

* migration doc update

* follow on androidx upgrade after rebase
This commit is contained in:
Greg Alexander 2019-06-02 15:20:57 -04:00 committed by Sibelius Seraphini
parent 54b03328b1
commit e2a895ad1c
33 changed files with 151 additions and 62 deletions

View File

@ -5,9 +5,6 @@ def safeExtGet(prop, fallback) {
buildscript {
repositories {
google()
maven {
url 'https://maven.google.com'
}
jcenter()
}
@ -64,9 +61,7 @@ android {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com'
}
mavenCentral()
maven { url "https://jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
@ -81,9 +76,9 @@ dependencies {
implementation "com.google.zxing:core:3.3.3"
implementation "com.drewnoakes:metadata-extractor:2.11.0"
generalImplementation "com.google.android.gms:play-services-vision:$googlePlayServicesVisionVersion"
implementation "com.android.support:exifinterface:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.android.support:support-annotations:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.android.support:support-v4:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "androidx.exifinterface:exifinterface:1.0.0"
implementation "androidx.annotation:annotation:1.0.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
mlkitImplementation "com.google.firebase:firebase-ml-vision:${safeExtGet('firebase-ml-vision', '19.0.3')}"
mlkitImplementation "com.google.firebase:firebase-ml-vision-face-model:${safeExtGet('firebase-ml-vision-face-model', '17.0.2')}"
}

View File

@ -0,0 +1,2 @@
android.enableJetifier=true
android.useAndroidX=true

View File

@ -1,4 +1,4 @@
#Sun Dec 31 13:43:56 BRST 2017
#Wed Jan 23 23:35:17 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -3,7 +3,7 @@ package org.reactnative.facedetector.tasks;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.media.ExifInterface;
import androidx.exifinterface.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

View File

@ -18,8 +18,8 @@ package com.google.android.cameraview;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.util.SparseArrayCompat;
import androidx.annotation.NonNull;
import androidx.collection.SparseArrayCompat;
/**
* Immutable class for describing proportional relationship between width and height.

View File

@ -24,7 +24,7 @@ import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Build;
import android.os.Handler;
import android.support.v4.util.SparseArrayCompat;
import androidx.collection.SparseArrayCompat;
import android.util.Log;
import android.view.SurfaceHolder;
@ -89,11 +89,11 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
private boolean mIsRecording;
private final SizeMap mPreviewSizes = new SizeMap();
private boolean mIsPreviewActive = false;
private final SizeMap mPictureSizes = new SizeMap();
private Size mPictureSize;
private AspectRatio mAspectRatio;
@ -209,7 +209,7 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
mCamera.setPreviewCallback(this);
}
}
@Override
public void resumePreview() {
startCameraPreview();
@ -253,12 +253,12 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
}
return idealAspectRatios.ratios();
}
@Override
SortedSet<Size> getAvailablePictureSizes(AspectRatio ratio) {
return mPictureSizes.sizes(ratio);
}
@Override
void setPictureSize(Size size) {
if (size == null) {
@ -278,7 +278,7 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
mCamera.setParameters(mCameraParameters);
}
}
@Override
Size getPictureSize() {
return mPictureSize;

View File

@ -37,7 +37,7 @@ import android.media.CamcorderProfile;
import android.media.Image;
import android.media.ImageReader;
import android.media.MediaRecorder;
import android.support.annotation.NonNull;
import androidx.annotation.NonNull;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.Surface;

View File

@ -24,12 +24,12 @@ import android.media.CamcorderProfile;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.os.ParcelableCompat;
import android.support.v4.os.ParcelableCompatCreatorCallbacks;
import android.support.v4.view.ViewCompat;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.os.ParcelableCompat;
import androidx.core.os.ParcelableCompatCreatorCallbacks;
import androidx.core.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

View File

@ -18,7 +18,7 @@ package com.google.android.cameraview;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import androidx.annotation.NonNull;
/**
* Immutable class for describing width and height dimensions in pixels.

View File

@ -16,7 +16,7 @@
package com.google.android.cameraview;
import android.support.v4.util.ArrayMap;
import androidx.collection.ArrayMap;
import java.util.Set;
import java.util.SortedSet;

View File

@ -17,7 +17,7 @@
package com.google.android.cameraview;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import androidx.core.view.ViewCompat;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

View File

@ -3,7 +3,7 @@ package com.lwansbrough.RCTCamera;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.support.media.ExifInterface;
import androidx.exifinterface.media.ExifInterface;
import android.util.Base64;
import android.util.Log;

View File

@ -1,6 +1,6 @@
package com.lwansbrough.RCTCamera;
import android.support.annotation.Nullable;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera;
import android.support.annotation.Nullable;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;

View File

@ -7,7 +7,7 @@ import android.graphics.Color;
import android.media.CamcorderProfile;
import android.media.MediaActionSound;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import androidx.core.content.ContextCompat;
import android.view.View;
import android.os.AsyncTask;
import com.facebook.react.bridge.*;

View File

@ -6,7 +6,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.media.CamcorderProfile;
import android.os.Build;
import android.support.media.ExifInterface;
import androidx.exifinterface.media.ExifInterface;
import android.view.ViewGroup;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import org.reactnative.camera.CameraViewManager;
import com.facebook.react.bridge.Arguments;
@ -11,7 +11,6 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import java.util.Date;
import java.util.Formatter;
public class BarCodeReadEvent extends Event<BarCodeReadEvent> {

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;

View File

@ -1,6 +1,7 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import org.reactnative.camera.CameraViewManager;
import com.facebook.react.bridge.Arguments;
@ -8,8 +8,6 @@ import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import java.util.Date;
public class CameraReadyEvent extends Event<CameraReadyEvent> {
private static final Pools.SynchronizedPool<CameraReadyEvent> EVENTS_POOL = new Pools.SynchronizedPool<>(3);
private CameraReadyEvent() {}

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import org.reactnative.camera.CameraViewManager;
import com.facebook.react.bridge.Arguments;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import org.reactnative.camera.CameraViewManager;
import com.facebook.react.bridge.Arguments;
@ -8,8 +8,6 @@ import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import java.util.Date;
public class PictureTakenEvent extends Event<PictureTakenEvent> {
private static final Pools.SynchronizedPool<PictureTakenEvent> EVENTS_POOL = new Pools.SynchronizedPool<>(3);
private PictureTakenEvent() {}

View File

@ -1,6 +1,6 @@
package org.reactnative.camera.events;
import android.support.v4.util.Pools;
import androidx.core.util.Pools;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableArray;

View File

@ -6,7 +6,7 @@ import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.media.ExifInterface;
import androidx.exifinterface.media.ExifInterface;
import android.util.Base64;
import org.reactnative.camera.RNCameraViewHelper;

View File

@ -1,7 +1,7 @@
package org.reactnative.facedetector.tasks;
import android.content.Context;
import android.support.media.ExifInterface;
import androidx.exifinterface.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

101
docs/AndroidXMigration.md Normal file
View File

@ -0,0 +1,101 @@
# AndroidX Migration
AndroidX is the replacement for Google Support Libraries. It is the open-source project that the Android team uses to
develop, test, package, version and release libraries within Jetpack. Moving forward, all new Android development
will be in AndroidX, the Support Libraries are depreciated.
> AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backwards-compatibility across Android releases. AndroidX fully replaces the Support Library by providing feature parity and new libraries.
See: https://developer.android.com/jetpack/androidx/
## Migration via Android studio
You can follow the instructions [here](https://developer.android.com/jetpack/androidx/migrate) to migrate you existing
project.
## Manual
#### Update the android section `android/app/build.gradle` to
```
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 28
}
...
```
If you have any `dependencies {` that are using the old Google Support Libraries, you'll need to update them
to use the androidx version. Can check the full migration list [here](https://developer.android.com/jetpack/androidx/migrate).
#### Update `android/app/src/main/AndroidManifest.xml`
remove
```xml
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
```
#### Update `android/build.gradle`
```
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven { url "https://jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
ext {
compileSdkVersion = 28
buildToolsVersion = '28.0.3'
}
subprojects { subproject ->
afterEvaluate{
if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
}
}
}
```
#### Update `android/gradle.properties`
add
```
android.enableJetifier = true;
android.useAndroidX = true;
```
#### Update `android/gradle/wrapper/gradle-wrapper.properties`
make sure your gradle `distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip`

View File

@ -137,7 +137,7 @@ android {
dependencies {
implementation project(':react-native-camera')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation "com.facebook.react:react-native:+" // From node_modules
}

View File

@ -9,10 +9,6 @@
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="26" />
<application
android:name=".MainApplication"
android:allowBackup="true"

View File

@ -23,15 +23,13 @@ buildscript {
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven { url "https://jitpack.io" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url "https://maven.google.com" // Google's Maven repository
}
maven { url "https://jitpack.io" }
}
}

View File

@ -18,4 +18,5 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=1g -XX:+HeapDumpOnOutOfMemoryError -Df
# org.gradle.parallel=true
android.useDeprecatedNdk=true
android.enableAapt2=false
android.enableJetifier=true
android.useAndroidX=true