Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] fixed issues with android debug build #901

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.nio.file.Paths

buildscript {
repositories {
google()
Expand All @@ -17,20 +19,39 @@ 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"
}


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")) {
Expand All @@ -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()) {
Expand All @@ -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:+'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 1 addition & 17 deletions docs/manual-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down