How can I add and compile local copy of a library into Android React Native module? - build.gradle

How Can I add to native module, external library source code.
In the case, I want to add a local copy of ExoPlayer to react-native-video module.
I want to "git clone" the original source of the ExoPlayer
inside react-native-video/android-exoplayer ,make some modifications on it and test it.
Currently the depencies of /react-native-video/android-exoplayer/build.gradle are:
dependencies {
//noinspection GradleDynamicVersion
provided "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
compile 'com.google.android.exoplayer:exoplayer:2.7.3'
compile('com.google.android.exoplayer:extension-okhttp:2.7.3') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
compile 'com.squareup.okhttp3:okhttp:3.9.1'
}
current file structure:
build
build.gradle
ExoPlayer
/src
This directory "ExoPlayer" I got with "git clone" and want to use instead of
compile 'com.google.android.exoplayer:exoplayer:2.7.3'

I found the solution:
In the root Project settings.gradle should add this:
gradle.ext.exoplayerRoot = '../node_modules/react-native-video/android-exoplayer/ExoPlayer-r2.7.3'
gradle.ext.exoplayerModulePrefix = 'exoplayer-'
apply from: new File(gradle.ext.exoplayerRoot, 'core_settings.gradle')
In react-native-video/android-exoplayer/build.gradle dependencies section add this:
implementation project(':exoplayer-library-core')
implementation project(':exoplayer-library-hls')
implementation project(':exoplayer-library-smoothstreaming')
implementation project(':exoplayer-library-dash')
implementation project(':exoplayer-library-ui')
implementation project(':exoplayer-extension-okhttp')
and remove all rows started with "compile"

Related

Import Polymer 2 components in Polymer 3

I am developing a web component using Polymer v3, and need to include some custom elements defined in legacy Polymer 2 components in the template HTML of my new component.
Since HTML imports are no longer supported in Polymer 3, what approach should I take to include them? If I was using Polymer 2 I could just add the following in my component's HTML file:
<link rel="import" href="../my-legacy-component.html">
I have tried adding the above link into the template HTML of my component, but it appears that doesn't work. I have also tried various import commands to reference the JS files inside the legacy component directly, but received various inscrutable JS errors so I'm not sure if that is the correct way to go either.
I can't believe there isn't a simple way to do this - would the Polymer team really introduce a new version of the library that is completely incompatible with all the components created using older versions?
Did you try to use polymer-modulizer?
Modulizer performs many different upgrade tasks, like:
Detects which .html files are used as HTML Imports and moves them to .js
Rewrites in HTML to import in JS.
Removes "module wrappers" - IIFEs that scopes your code.
Converts bower.json to package.json, using the corresponding packages on npm.
Converts "namespace references" to the proper JS module import, ie: Polymer.Async.timeOut to timeOut as imported from #polymer/polymer/lib/util/async.
Creates exports for values assigned to namespace referencs. ie, Foo.bar = {...} becomes export const bar = {...}
Rewrites namespace objects - an object with many members intended to be used as a module-like object, to JS modules.
Moves Polymer element templates from HTML into a JS template string.
Removes s if they only contained a template.
Moves other generic HTML in the document into a JS string and creates it when the module runs.
more on github
I have ran into the same problem with the module js-yaml earlier. I don't have enough reputation for a comment yet so I just write it down here.
Run this sudo npm install -g js-yaml -> This will install the missing package for the tool
Then at the root of your project, run modulizer --import-style name --out . -> This will convert your component from Polymer 2 to Polymer 3. The option --import-style name tells the tool to use package name instead of path. --out will make the tool writes those files to the directory.
After that, if no error prompts. Try to serve it with polymer serve --module-resolution=node -> Since we are using node modules now, we have to provide the --module-resolution=node option.

immutable flow fails . live test on travis

Hello this questions is having a minimal working example of what Im trying to build.
Im having troubles to run flow-type checker on just simple JS file. Here is how the file looks like
// #flow
import type { Map } from 'immutable';
And I even build a minimal working (NOT working) example with travis running it.
Here is the repository. It's very simple and only has flow and immutable-js dependencies.
https://github.com/RusAlex/immutable-flow
and here is the failed Travis-ci build
https://travis-ci.org/RusAlex/immutable-flow/builds/243260858
Flow reads the package.json to find out about imports, but since you moved your .flowconfig inside your src/ folder, it no longer can. If you include the package.json by adding ../package.json to your [include] you get an interesting error:
src/flow.js:2
2: import { Map } from 'immutable';
^^^^^^^^^^^ This modules resolves to "<<PROJECT_ROOT>>/../node_modules/immutable/package.json", which is outside both your root directory and all of the entries in the [include] section of your .flowconfig. You should either add this directory to the [include] section of your .flowconfig, move your .flowconfig file higher in the project directory tree, or move this package under your Flow root directory.
Finally, adding ../node_modules/immutable/ will help flow resolve everything again.
Alternatively, you could just add .flowconfig to the actual project root. It makes things simpler and seems to be the intended default.

Sharing components across multiple Aurelia projects

we started our project with ES6 javascript skeleton.
we would like to extract some styles and custom attributes to a common folder so we can use these at any Aurelia module we will build in the future.
the problem is with the bundle files. we don't know how to config them to bundle external folder out of the main ES6 folder.
can you please tell us what to do?
It sounds like you want to build an Aurelia plugin that you can import into any project. I would start by taking a look at the Aurelia plugin skeleton.
Once you've built your plugin with the custom styles and attributes you want, you'll want to either register it with jspm as a link, or publically through a registry such as npm or github.
Once published, you will be able to jspm install registry:my-package in any new project, and add the following line to your main.js file:
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.plugin('my-package');
}
For more information on this last step, see the brilliant answer provided by Ashley Grant here.

How to validate JSON in Gradle build

I have a Gradle build where a large JSON configuration is bundled into a package for later upload onto a server. Sometimes when changes are made to the file, the file is not valid any more and thus fails to upload on the server.
I would like to find this earlier by adding a validate-step in the Gradle build.
When looking around I could not find a documented way to do this, I saw the project gradle-json-validator which looks promising, but there is no documentation whatsoever, so I am not sure how this can be used...
Any hint on gradle-json-validator or any other way to validate a JSON file as part of the Gradle build steps?
From source, it would seem, the usage would be:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'cz.alenkacz.gradle:json-validator:0.9.9'
}
}
apply plugin: 'cz.alenkacz.gradle.jsonvalidator'
The plugin doesn't seem to have an extension to do configuration. But seems to use jsonSchema and targetJsonFile as input schema and file-to-validate. I would try setting them at the root level of build.gradle
validateJson.jsonSchema = new File('/path/to/schema')
validateJson.targetJsonFile = new File('/path/to/jsonFile')
and the task to run is:
gradle validateJson
I have improved the readme file in the repository with proper usage example.
Hope that helps. https://github.com/alenkacz/gradle-json-validator

Unable to update file in appDataFolder using Google Drive REST API V3 on Android

This is the code i'm using to update the file.
File metadata = generateFileMetadata(fileId, thumbnail, properties);
return mService.files().update(fileId, metadata, generateFileContents())
.setFields("id, name, appProperties")
.execute();
This code generates a
java.lang.IllegalArgumentException.
at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:111)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:37)
at com.google.api.client.googleapis.media.MediaHttpUploader.setInitiationRequestMethod(MediaHttpUploader.java:872)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.initializeMediaUpload(AbstractGoogleClientRequest.java:237)
at com.google.api.services.drive.Drive$Files$Update.<init>(Drive.java:3163)
at com.google.api.services.drive.Drive$Files.update(Drive.java:3113)
Using breakpoints I could see that the String passed to the setInitiationRequestMethod is PATCH (not POST or PUT):
public MediaHttpUploader setInitiationRequestMethod(String initiationRequestMethod) {
Preconditions.checkArgument(initiationRequestMethod.equals(HttpMethods.POST)
|| initiationRequestMethod.equals(HttpMethods.PUT));
this.initiationRequestMethod = initiationRequestMethod;
return this;
}
this is what i have in my build.gradle
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile('com.google.api-client:google-api-client-android:1.21.0') {
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.apis:google-api-services-drive:v3-rev11-1.21.0') {
exclude group: 'org.apache.httpcomponents'
}
if I remove the file content (generateFileContents()) I'm able to update the metadata just fine.
How do I solve this?
I ran into this bug while writing a Drive REST API integration for an Android app (with Android Studio/Gradle). Since I'm not particularly experienced with Android's build system, resolving the issue cost me a few hours. Maybe this helps somebody with the same problem:
Clone the google-api-java-client repo from GitHub https://github.com/google/google-api-java-client
Install Maven https://maven.apache.org/run-maven/ (e.g. brew install maven on OSX)
On the command line, change into the google-api-client sub dir of the repo you cloned above
Run mvn clean install
This will produce a subdir called target in the google-api-client directory
In there, find google-api-client-1.22.0-SNAPSHOT.jar, rename it to google-api-client-1.21.00.jar (the renaming is probably not needed)
Drop the .jar in the libs folder of your android project
Tell Gradle to ignore the google-api-client dependency of the libraries you use, in my case this was:
compile('com.google.api-client:google-api-client-android:1.21.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'google-api-client'
}
compile('com.google.apis:google-api-services-drive:v3-rev14-1.21.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'google-api-client'
}
Add the Jackson dependency again, in case you miss it now. Do the same with other google-api-java-client dependencies if you need them.
compile('com.google.http-client:google-http-client-jackson2:1.21.0'){
exclude group: 'org.apache.httpcomponents'
}
Build your project, update(...) should now work.
Make a note to scrap these changes once Google has updated the library.
Take a look at the current commit of the google-api-java-client.
Unfortunately the fix was not released yet (fix on 21 Nov 2015 vs release on 19 Nov 2015), so you may have to build locally the project (with maven for instance)
The MediaHttpUploader javadocs suggests that it will only be used for HttpMethods#POST, and HttpMethods#UPDATE. Using update, based on the Files resource, indicates its using a PATCH method - leading to the IllegalArgumentException.
The overridden update method should only be used if you're uploading media content.
I have the same exception in a Desktop application.
Instead, using the Drive Api V2, the update goes well.