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

feat(android): simple installation #414

Merged
merged 5 commits into from
May 29, 2022
Merged
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
29 changes: 1 addition & 28 deletions docs/react-native/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,7 @@ yarn add @notifee/react-native
```


## 2. Android: Add local maven repository

The Notifee core library is packaged an Android "AAR" file. It is distributed in a "local maven repository" for Android integration.

You must add this repository to your `android/build.gradle` build script file.

Open `android/build.gradle` for editing, and add these lines in your `allprojects` `repositories` section:


```groovy

allprojects {

// ... you may have other items before the "repositories" section, that is fine

repositories {

// ... you will already have some local repositories defined ...

// ADD THIS BLOCK - this is how Notifee finds its Android library:
maven {
url "$rootDir/../node_modules/@notifee/react-native/android/libs"
}
}
}
```

## 3. Autolinking with React Native
## 2. Autolinking with React Native
Users on React Native 0.60+ automatically have access to "[autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md)",
requiring no further manual installation steps. To automatically link the package, rebuild your project:

Expand Down
7 changes: 7 additions & 0 deletions packages/react-native/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,10 @@ ReactNative.shared.applyPackageVersion()
ReactNative.shared.applyDefaultExcludes()
ReactNative.module.applyAndroidVersions()
ReactNative.module.applyReactNativeDependency("api")
rootProject.allprojects {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christocracy - you might like this, removes an error-prone install step for react-native repos with local maven repositories to load aars, appears to work fine for us here, could clean up my app build files from background-fetch and geolocation-android :-)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, cool!!

repositories {
maven {
url "$rootDir/../node_modules/@notifee/react-native/android/libs"
}
}
}
3 changes: 1 addition & 2 deletions packages/react-native/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
compileSdkVersion = 31
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
}
Expand All @@ -23,7 +23,6 @@ allprojects {
repositories {
mavenCentral()
mavenLocal()
maven { url "$rootDir/../node_modules/@notifee/react-native/android/libs" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"postinstall": "cd node_modules/@notifee/react-native && yarn"
},
"dependencies": {
"@notifee/react-native": "github:notifee/react-native-notifee",
"@notifee/react-native": "link:../",
Comment on lines 13 to +14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I linked to the current project to check the build with changes, please let me know if a revert is needed!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this was there for some reason, but in retrospect I can't remember what it is. I think the link to local is better personally and I'd like it to work. Willing to go with it and see if it works, personally

"react": "17.0.2",
"react-native": "0.66.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ buildscript {
allprojects {
repositories {
mavenLocal()
maven { url \\"$rootDir/../node_modules/@notifee/react-native/android/libs\\" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url(\\"$rootDir/../node_modules/react-native/android\\")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import path from 'path';

import { setCompileSdkVersion, setMavenRepository } from '../src/withNotifeeProjectGradlePlugin';
import { setCompileSdkVersion } from '../src/withNotifeeProjectGradlePlugin';

const getProjectGradle = () => {
return fs.readFile(path.resolve(__dirname, './fixtures/project.build.gradle'), {
Expand All @@ -16,11 +16,4 @@ describe('[Android] project build.gradle test', () => {

expect(newProjectGradle).toContain('compileSdkVersion = 31');
});

it('adds custom maven repository to project build.gradle', async () => {
const projectGradle = await getProjectGradle();
const newProjectGradle = setMavenRepository(projectGradle);

expect(newProjectGradle).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const withNotifeeProjectGradlePlugin: ConfigPlugin = config => {
}

modResults.contents = setCompileSdkVersion(modResults.contents);
modResults.contents = setMavenRepository(modResults.contents);
return { modResults, ...subConfig };
});
};
Expand All @@ -24,15 +23,5 @@ const setCompileSdkVersion = (buildGradle: string): string => {
return buildGradle.replace(/compileSdkVersion = 30/, `compileSdkVersion = 31`);
};

const setMavenRepository = (projectBuildGradle: string): string => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you got the expo plugin too, I forgot about it 🤦 - nicely done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd never know if you hadn't told me about the tests. 👍

if (projectBuildGradle.includes('@notifee/react-native/android/libs')) return projectBuildGradle;

return projectBuildGradle.replace(
/mavenLocal\(\)/,
`mavenLocal()
maven { url "$rootDir/../node_modules/@notifee/react-native/android/libs" }`,
);
};

export { setCompileSdkVersion, setMavenRepository };
export { setCompileSdkVersion };
export default withNotifeeProjectGradlePlugin;
3 changes: 0 additions & 3 deletions tests_react_native/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ allprojects {
maven {
url "$rootDir/../node_modules/detox/Detox-android"
}
maven {
url "$rootDir/../node_modules/@notifee/react-native/android/libs"
}
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
Expand Down
10 changes: 5 additions & 5 deletions tests_react_native/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ PODS:
- Firebase/Messaging (= 8.12.1)
- React-Core
- RNFBApp
- RNNotifee (5.0.2):
- RNNotifee (5.2.2):
- NotifeeCore
- React-Core
- RNNotifeeCore (5.0.2):
- RNNotifeeCore (5.2.2):
- NotifeeCore
- Yoga (1.14.0)

Expand Down Expand Up @@ -546,10 +546,10 @@ SPEC CHECKSUMS:
ReactCommon: 650e33cde4fb7d36781cd3143f5276da0abb2f96
RNFBApp: 5bae3002117e55f3c9aa0fb38175dd16c8046c90
RNFBMessaging: ae6c40883868cd01fa802395174ec7d61cfa0920
RNNotifee: 2e77e7e79138950470fdb14a5c3f0d4659499871
RNNotifeeCore: d5a2d465b7ab75f87067324e823fdfdbc992f0e5
RNNotifee: e300470c3a2dff82bdc5f904d0fa88de9e3a03ad
RNNotifeeCore: 500d628692336ea9f47b693109c7b53508a788bf
Yoga: 90dcd029e45d8a7c1ff059e8b3c6612ff409061a

PODFILE CHECKSUM: 7b5b8be1d1de29d123a78ccb5cad509690e4f8d0

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3