Skip to content

Commit

Permalink
[Android] Adds Maven Support For Gradle Dependency [xx]
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thorbenprimke committed Jun 14, 2019
1 parent c7e933c commit 18f99f2
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 3 deletions.
15 changes: 15 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
README
======

Steps before publishing a new version to npm:

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
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
```
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/{username}/Library/Android/sdk
```
3. Delete the `maven` folder
4. Run `sudo ./gradlew installArchives`
5. Verify that latest set of generated files is in the maven folder with the correct version number

94 changes: 93 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
}
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

def DEFAULT_COMPILE_SDK_VERSION = 26
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.2"
Expand All @@ -19,6 +31,86 @@ android {
}
}

repositories {
google()
jcenter()
maven {
url "$projectDir/../node_modules/react-native/android"
}
mavenCentral()
}

dependencies {
compileOnly 'com.facebook.react:react-native:+'
}
}

def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

pom.project {
name "React Native Sound"
artifactId packageJson.name
version = packageJson.version
group = "com.zmxv.RNSound"
description packageJson.description
url packageJson.repository.baseUrl

licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}

developers {
developer {
id 'zmxv'
name packageJson.author.name
}
}
}
}

afterEvaluate { project ->

task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
from variant.javaCompile.destinationDir
}
}

artifacts {
archives androidSourcesJar
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"

configureReactNativePom pom
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60106aaefd1651dfce923a4471716e21
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dd52b4d751cec99c67422ad6a7a4eba7d8d347e6
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1bcef3718951fc026eccd47926697f4d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2855b2257d3f4a718bd4863ca57a7cd9562091aa
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
203e4fc952c468155bb4b9e689270736
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c48e14575bba63f2e3f271f0e56070745239a79d
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zmxv.RNSound</groupId>
<artifactId>react-native-sound</artifactId>
<version>0.10.12</version>
<packaging>aar</packaging>
<name>React Native Sound</name>
<description>React Native module for playing sound clips on iOS, Android, and Windows</description>
<url>null</url>
<licenses>
<license>
<name>MIT</name>
<url>null/blob/master/null</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>zmxv</id>
<name>Zhen Wang (http://blog.zmxv.com)</name>
</developer>
</developers>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc939039245e899b4bc7457de3c3e6cf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
53f0cb9cfd309dfd902d2f6690f2d4b805db62f3
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.zmxv.RNSound</groupId>
<artifactId>react-native-sound</artifactId>
<versioning>
<release>0.10.12</release>
<versions>
<version>0.10.12</version>
</versions>
<lastUpdated>20190614175543</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79e5fc5cdd7143aaabc5561945558b4c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e17070c134bc996b14a099b3f807b581da900a90
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
"sound",
"audio"
],
"author": "Zhen Wang <[email protected]> (http://blog.zmxv.com)",
"author": {
"name": "Zhen Wang (http://blog.zmxv.com)",
"email": "[email protected]"
},
"license": "MIT",
"devDependencies": {
"react-native": "0.59.9"
},
"peerDependencies": {
"react-native": ">=0.8.0"
}
}
}

0 comments on commit 18f99f2

Please sign in to comment.