Skip to content

Commit 18f99f2

Browse files
author
Thorben Primke
committed
[Android] Adds Maven Support For Gradle Dependency [xx]
Summary: In order to easily include RN Sound in a brownfield project, this sets up the maven dependency generation. The maven files can then be referenced similary to how RN is referenced in that it no longer requires adding the native dependency to the node modules folder. Test plan: - verified generated maven files work as expected
1 parent c7e933c commit 18f99f2

18 files changed

+163
-3
lines changed

android/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
README
2+
======
3+
4+
Steps before publishing a new version to npm:
5+
6+
1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
7+
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
8+
```
9+
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
10+
sdk.dir=/Users/{username}/Library/Android/sdk
11+
```
12+
3. Delete the `maven` folder
13+
4. Run `sudo ./gradlew installArchives`
14+
5. Verify that latest set of generated files is in the maven folder with the correct version number
15+

android/build.gradle

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
jcenter()
5+
}
6+
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:3.1.4'
9+
}
10+
}
11+
112
apply plugin: 'com.android.library'
13+
apply plugin: 'maven'
214

315
def DEFAULT_COMPILE_SDK_VERSION = 26
416
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.2"
@@ -19,6 +31,86 @@ android {
1931
}
2032
}
2133

34+
repositories {
35+
google()
36+
jcenter()
37+
maven {
38+
url "$projectDir/../node_modules/react-native/android"
39+
}
40+
mavenCentral()
41+
}
42+
2243
dependencies {
2344
compileOnly 'com.facebook.react:react-native:+'
24-
}
45+
}
46+
47+
def configureReactNativePom(def pom) {
48+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
49+
50+
pom.project {
51+
name "React Native Sound"
52+
artifactId packageJson.name
53+
version = packageJson.version
54+
group = "com.zmxv.RNSound"
55+
description packageJson.description
56+
url packageJson.repository.baseUrl
57+
58+
licenses {
59+
license {
60+
name packageJson.license
61+
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
62+
distribution 'repo'
63+
}
64+
}
65+
66+
developers {
67+
developer {
68+
id 'zmxv'
69+
name packageJson.author.name
70+
}
71+
}
72+
}
73+
}
74+
75+
afterEvaluate { project ->
76+
77+
task androidJavadoc(type: Javadoc) {
78+
source = android.sourceSets.main.java.srcDirs
79+
classpath += files(android.bootClasspath)
80+
classpath += files(project.getConfigurations().getByName('compile').asList())
81+
include '**/*.java'
82+
}
83+
84+
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
85+
classifier = 'javadoc'
86+
from androidJavadoc.destinationDir
87+
}
88+
89+
task androidSourcesJar(type: Jar) {
90+
classifier = 'sources'
91+
from android.sourceSets.main.java.srcDirs
92+
include '**/*.java'
93+
}
94+
95+
android.libraryVariants.all { variant ->
96+
def name = variant.name.capitalize()
97+
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
98+
from variant.javaCompile.destinationDir
99+
}
100+
}
101+
102+
artifacts {
103+
archives androidSourcesJar
104+
archives androidJavadocJar
105+
}
106+
107+
task installArchives(type: Upload) {
108+
configuration = configurations.archives
109+
repositories.mavenDeployer {
110+
// Deploy to react-native-event-bridge/maven, ready to publish to npm
111+
repository url: "file://${projectDir}/../android/maven"
112+
113+
configureReactNativePom pom
114+
}
115+
}
116+
}
22.8 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
60106aaefd1651dfce923a4471716e21
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dd52b4d751cec99c67422ad6a7a4eba7d8d347e6
4.12 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1bcef3718951fc026eccd47926697f4d
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2855b2257d3f4a718bd4863ca57a7cd9562091aa
11.3 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
203e4fc952c468155bb4b9e689270736

0 commit comments

Comments
 (0)