diff --git a/android/build.gradle b/android/build.gradle index 20cc6954..bcfce4a0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,3 +1,5 @@ +import java.nio.file.Paths + buildscript { repositories { google() @@ -17,6 +19,20 @@ def isNewArchitectureEnabled() { return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" } +static def findNodeModulePath(baseDir, packageName) { + def basePath = baseDir.toPath().normalize() + // Node's module resolution algorithm searches up to the root directory, + // after which the base path will be null + while (basePath) { + def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName) + if (candidatePath.toFile().exists()) { + return candidatePath.toString() + } + basePath = basePath.getParent() + } + return null +} + apply plugin: 'com.android.library' if (isNewArchitectureEnabled()) { apply plugin: "com.facebook.react" @@ -24,13 +40,18 @@ if (isNewArchitectureEnabled()) { android { - def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION - if (agpVersion.tokenize('.')[0].toInteger() >= 7) { - namespace "com.reactcommunity.rndatetimepicker" - } - compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') + def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') + def majorVersion = agpVersion[0].toInteger() + def minorVersion = agpVersion[1].toInteger() + + if ((majorVersion == 7 && minorVersion >= 3) || majorVersion > 7) { + namespace "com.reactcommunity.rndatetimepicker" + buildFeatures { + buildConfig true + } + } // Used to override the NDK path/version on internal CI or by allowing // users to customize the NDK path/version from their root project (e.g. for M1 support) if (rootProject.hasProperty("ndkPath")) { @@ -46,6 +67,13 @@ android { buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() } + if (majorVersion < 8) { + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + } + sourceSets.main { java { if (!isNewArchitectureEnabled()) { @@ -55,13 +83,17 @@ android { } } +def reactNativePath = findNodeModulePath(projectDir, "react-native") + repositories { + maven { + url "${reactNativePath}/android" + } google() - mavenLocal() mavenCentral() } dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' -} +} \ No newline at end of file diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java index 6eec370b..fb3e536a 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/DatePickerModule.java @@ -35,6 +35,11 @@ public class DatePickerModule extends NativeModuleDatePickerSpec { @VisibleForTesting public static final String NAME = "RNCDatePicker"; + @Override + public boolean canOverrideExistingModule() { + return true; + } + public DatePickerModule(ReactApplicationContext reactContext) { super(reactContext); } diff --git a/docs/manual-installation.md b/docs/manual-installation.md index 8684fce2..da89bec1 100644 --- a/docs/manual-installation.md +++ b/docs/manual-installation.md @@ -47,23 +47,7 @@ #### Android -1. Add the following lines to `android/settings.gradle`: - - ```gradle - include ':@react-native-community_datetimepicker' - project(':@react-native-community_datetimepicker').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/datetimepicker/android') - ``` - -2. Add the compile line to the dependencies in `android/app/build.gradle`: - - ```gradle - dependencies { - ... - implementation project(':@react-native-community_datetimepicker') - } - ``` - -3. Add the import and link the package in `MainApplication.java`: +Add the import and link the package in `MainApplication.java`: ```diff + import com.reactcommunity.rndatetimepicker.RNDateTimePickerPackage;