Skip to content

Commit

Permalink
Update link command for Android project (#20853)
Browse files Browse the repository at this point in the history
Summary:
Motivation:
--------------
PR #20767 bumped the version of the Android Gradle Plugin to v3 which uses the newer Gradle dependency configurations `implementation` and `api` which make `compile` obsolete.

While the PR updated the template Gradle configuration, it did not cover the `link` command which will still link native modules using `compile` resulting in a warning message beeing displayed during an app build.

Since `compile` will be eventually removed by Gradle, this commit updates the `link` command to attach native modules using `implementation`.
Pull Request resolved: facebook/react-native#20853

Differential Revision: D9733888

Pulled By: hramos

fbshipit-source-id: 22853480d7ba7be65e3387effda2fd6c72b6906a
  • Loading branch information
matei-radu authored and facebook-github-bot committed Sep 8, 2018
1 parent 26888a5 commit c6c34a2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions link/__fixtures__/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:27.1.1"
compile "com.facebook.react:react-native:+"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.facebook.react:react-native:+"
}
10 changes: 5 additions & 5 deletions link/__fixtures__/android/patchedBuild.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies {
compile project(':test')
compile(project(':test2')) {
implementation project(':test')
implementation(project(':test2')) {
exclude(group: 'org.unwanted', module: 'test10')
}
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:27.1.1"
compile "com.facebook.react:react-native:+"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.facebook.react:react-native:+"
}
10 changes: 6 additions & 4 deletions link/__tests__/android/makeBuildPatch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ describe('makeBuildPatch', () => {

it('should make a correct patch', () => {
const {patch} = makeBuildPatch(name);
expect(patch).toBe(` compile project(':${name}')\n`);
expect(patch).toBe(` implementation project(':${name}')\n`);
});

it('should make a correct install check pattern', () => {
const {installPattern} = makeBuildPatch(name);
const match = `/\\s{4}(compile)(\\(|\\s)(project)\\(\\':${name}\\'\\)(\\)|\\s)/`;
const match = `/\\s{4}(implementation)(\\(|\\s)(project)\\(\\':${name}\\'\\)(\\)|\\s)/`;
expect(installPattern.toString()).toBe(match);
});
});

describe('makeBuildPatchWithScopedPackage', () => {
it('should make a correct patch', () => {
const {patch} = makeBuildPatch(scopedName);
expect(patch).toBe(` compile project(':${normalizedScopedName}')\n`);
expect(patch).toBe(
` implementation project(':${normalizedScopedName}')\n`,
);
});

it('should make a correct install check pattern', () => {
const {installPattern} = makeBuildPatch(scopedName);
const match = `/\\s{4}(compile)(\\(|\\s)(project)\\(\\':${normalizedScopedName}\\'\\)(\\)|\\s)/`;
const match = `/\\s{4}(implementation)(\\(|\\s)(project)\\(\\':${normalizedScopedName}\\'\\)(\\)|\\s)/`;
expect(installPattern.toString()).toBe(match);
});
});
4 changes: 2 additions & 2 deletions link/android/patches/makeBuildPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const normalizeProjectName = require('./normalizeProjectName');
module.exports = function makeBuildPatch(name) {
const normalizedProjectName = normalizeProjectName(name);
const installPattern = new RegExp(
`\\s{4}(compile)(\\(|\\s)(project)\\(\\\':${normalizedProjectName}\\\'\\)(\\)|\\s)`,
`\\s{4}(implementation)(\\(|\\s)(project)\\(\\\':${normalizedProjectName}\\\'\\)(\\)|\\s)`,
);

return {
installPattern,
pattern: /[^ \t]dependencies {(\r\n|\n)/,
patch: ` compile project(':${normalizedProjectName}')\n`,
patch: ` implementation project(':${normalizedProjectName}')\n`,
};
};

0 comments on commit c6c34a2

Please sign in to comment.