Importing tensorflow into Scala - scala

I have installed Tensorflow for Scala on my OSX, and although everything seemed fine, I have a NoClassDefFoundError when trying to run simple example like that –
import org.platanios.tensorflow.api.Tensor
val tensor = Tensor( 1.2, 4.5)
which gives:
java.lang.NoClassDefFoundError: Could not initialize class org.platanios.tensorflow.api.package$
at #worksheet#.tensor$lzycompute(testone.sc:3)
at #worksheet#.tensor(testone.sc:3)
at #worksheet#.get$$instance$$tensor(testone.sc:3)
at A$A16$.main(testone.sc:17)
at A$A16.main(testone.sc)
at #worksheet#.#worksheet#(testone.sc)
Similar error both on a Jupyter Notebook and an IntelliJ worksheet. My build.sbt:
scalaVersion := "2.12.4"
resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies += "org.platanios" %% "tensorflow" % "0.1.2-SNAPSHOT"
libraryDependencies += "org.platanios" %% "tensorflow" % "0.1.2-SNAPSHOT" classifier "darwin-cpu-x86_64"

The problem could be due to a missing dependency library of libtensorflow_jni.so contained by the scala_tensorflow jar
To find the missing library:
sbt console
then from the scala shell import the tensorflow api:
scala> import org.platanios.tensorflow.api._
scala> val tensor = Tensor.zeros(INT32, Shape(2, 5))
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/angelo/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/angelo/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN No appenders could be found for logger (TensorFlow Native).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.lang.UnsatisfiedLinkError: /tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow_jni.so: libcusolver.so.9.0: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at org.platanios.tensorflow.jni.TensorFlow$$anonfun$load$3.apply(TensorFlow.scala:95)
at org.platanios.tensorflow.jni.TensorFlow$$anonfun$load$3.apply(TensorFlow.scala:93)
at scala.Option.foreach(Option.scala:257)
at org.platanios.tensorflow.jni.TensorFlow$.load(TensorFlow.scala:93)
at org.platanios.tensorflow.jni.TensorFlow$.<init>(TensorFlow.scala:155)
at org.platanios.tensorflow.jni.TensorFlow$.<clinit>(TensorFlow.scala)
at org.platanios.tensorflow.jni.Tensor$.<init>(Tensor.scala:24)
at org.platanios.tensorflow.jni.Tensor$.<clinit>(Tensor.scala)
at org.platanios.tensorflow.api.tensors.Context$.apply(Context.scala:50)
at org.platanios.tensorflow.api.package$.<init>(package.scala:89)
at org.platanios.tensorflow.api.package$.<clinit>(package.scala)
... 40 elided
You can check all the missing libraries using ldd on another terminal (ldd in linux or otool -L on macosx):
ldd /tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow_jni.so
/tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow_jni.so: /usr/lib/libcublas.so.9.0: version `libcublas.so.9.0' not found (required by /tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow.so)
/tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow_jni.so: /usr/lib/libcublas.so.9.0: version `libcublas.so.9.0' not found (required by /tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow_framework.so)
linux-vdso.so.1 => (0x00007ffc00d85000)
libdlfaker.so => /usr/lib/x86_64-linux-gnu/libdlfaker.so (0x00007f0cd05d8000)
librrfaker.so => /usr/lib/x86_64-linux-gnu/librrfaker.so (0x00007f0cd033d000)
libtensorflow.so => /tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow.so (0x00007f0cc8023000)
libtensorflow_framework.so => /tmp/tensorflow_scala_native_libraries3327494822622243889/libtensorflow_framework.so (0x00007f0cc714b000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0cc6dc9000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0cc6bb3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0cc67e9000)
libGL.so.1 => /usr/lib/nvidia-390/libGL.so.1 (0x00007f0cc64ac000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0cc62a8000)
libturbojpeg.so.0 => /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0 (0x00007f0cc6047000)
libXv.so.1 => /usr/lib/x86_64-linux-gnu/libXv.so.1 (0x00007f0cc5e42000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f0cc5b08000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f0cc58f6000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0cc56d9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0cc53d0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0cd0a66000)
libcublas.so.9.0 => /usr/lib/libcublas.so.9.0 (0x00007f0cc1caf000)
libcusolver.so.9.0 => not found
libcudart.so.9.0 => not found
libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f0cc1a8d000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0cc1885000)
libcuda.so.1 => /usr/lib/x86_64-linux-gnu/libcuda.so.1 (0x00007f0cc0ce5000)
libcudnn.so.7 => /usr/local/cuda-9.1/targets/x86_64-linux/lib/libcudnn.so.7 (0x00007f0cafd54000)
libcufft.so.9.0 => not found
libcurand.so.9.0 => not found
libcudart.so.9.0 => not found
libnvidia-tls.so.390.30 => /usr/lib/nvidia-390/tls/libnvidia-tls.so.390.30 (0x00007f0cafb50000)
libnvidia-glcore.so.390.30 => /usr/lib/nvidia-390/libnvidia-glcore.so.390.30 (0x00007f0cadd50000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f0cadb2e000)
libnvidia-fatbinaryloader.so.390.30 => /usr/lib/nvidia-390/libnvidia-fatbinaryloader.so.390.30 (0x00007f0cad8e2000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f0cad6de000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f0cad4d8000)
On my computer the rutime linking process cannot resolve libcusolver.so.9.0 since I have installed cuda-9.1
To make it working I had to compile tensorflow as follows:
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
./configure
bazel build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --config=opt //tensorflow:libtensorflow.so
Copy the libraries into a path which is in LD_LIBRARY_PATH:
sudo cp bazel-bin/tensorflow/libtensorflow.so /usr/local/lib
sudo cp bazel-bin/tensorflow/libtensorflow_framework.so /usr/local/lib
Finally I was able to compile the tensorflow_scala project:
sbt compile
Now from the tensorflow_scala project I can run sbt console and it works:
scala> import org.platanios.tensorflow.api._
import org.platanios.tensorflow.api._
scala> val tensor = Tensor.zeros(INT32, Shape(2, 5))
2018-02-16 17:08:26.184 [run-main-0] INFO TensorFlow Native - Extracting the 'tensorflow_jni' native library to /tmp/tensorflow_scala_native_libraries8283851378265055495/libtensorflow_jni.so.
2018-02-16 17:08:26.188 [run-main-0] INFO TensorFlow Native - Copied 645872 bytes to /tmp/tensorflow_scala_native_libraries8283851378265055495/libtensorflow_jni.so.
2018-02-16 17:08:26.254 [run-main-0] INFO TensorFlow Native - Extracting the 'tensorflow_ops' native library to /tmp/tensorflow_scala_native_libraries8283851378265055495/libtensorflow_ops.so.
2018-02-16 17:08:26.254 [run-main-0] INFO TensorFlow Native - Copied 78232 bytes to /tmp/tensorflow_scala_native_libraries8283851378265055495/libtensorflow_ops.so.
2018-02-16 17:08:26.449239: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-02-16 17:08:26.449483: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1331] Found device 0 with properties:
name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.493
pciBusID: 0000:01:00.0
totalMemory: 3,95GiB freeMemory: 1,53GiB
2018-02-16 17:08:26.449498: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1410] Adding visible gpu devices: 0
2018-02-16 17:08:26.670568: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-02-16 17:08:26.670601: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917] 0
2018-02-16 17:08:26.670610: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0: N
2018-02-16 17:08:26.670698: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1021] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1287 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
2018-02-16 17:08:26.698355: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1410] Adding visible gpu devices: 0
2018-02-16 17:08:26.698399: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-02-16 17:08:26.698408: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917] 0
2018-02-16 17:08:26.698414: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0: N
2018-02-16 17:08:26.698518: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1021] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 224 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
tensor: org.platanios.tensorflow.api.tensors.Tensor = INT32[2, 5]
To use the locally built tensorflow_scala:
sbt
sbt:TensorFlow for Scala> + publishLocal
The jar will be placed into ~/.ivy2/local/org.platanios ; then you can add the jar to your sbt project e.g:
libraryDependencies ++= { Seq("org.platanios" %% "tensorflow" % "0.1.2-SNAPSHOT") }

Related

Wildfly : ClassNotFoundException: org.apache.xerces.parsers.SAXParser when deploying

I'm facing this error when deploying a war containing a spring-ws:
{"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operatio
n step-2" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"FLUX-WSApp.war\".undertow-deploym
ent" => "org.springframework.beans.factory.BeanCreationException: Error creating bean
...
Caused by: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser from [Module \"deployment.FLUX-WSApp.
war\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser from [Module \"deploym
ent.FLUX-WSApp.war\" from Service Module Loader]"}}}}
So I looked if the module was loaded (he is):
/core-service=module-loading:module-info(name=org.apache.xerces)
{
"outcome" => "success",
"result" => {
"name" => "org.apache.xerces",
"main-class" => undefined,
"fallback-loader" => undefined,
"dependencies" => [
{
"dependency-name" => "ModuleDependency",
"module-name" => "java.base",
"export-filter" => "Reject",
"import-filter" => "multi-path filter {exclude children of \"META-INF/\", exclude equals \"
META-INF\", default accept}",
"optional" => false
},
{
"dependency-name" => "ModuleDependency",
"module-name" => "jdk.xml.dom",
"export-filter" => "Reject",
"import-filter" => "multi-path filter {exclude children of \"META-INF/\", exclude equals \"
META-INF\", default accept}",
"optional" => false
},
{
"dependency-name" => "ModuleDependency",
"module-name" => "java.xml",
"export-filter" => "Reject",
"import-filter" => "multi-path filter {exclude children of \"META-INF/\", exclude equals \"
META-INF\", default accept}",
"optional" => false
}
],
"local-loader-class" => undefined,
"resource-loaders" => [
{
"type" => "org.jboss.modules.JarFileResourceLoader",
"paths" => [
"",
"org/w3c/dom/html",
"org/w3c",
"org/apache/xerces/xni/parser",
"org/apache/xerces/xpointer",
"META-INF/maven/xerces/xercesImpl",
"org/apache/xerces/impl/xpath/regex",
"org/apache/html",
"org/apache/xerces/impl/dv",
"org/apache/html/dom",
"org/apache/wml",
"org/w3c/dom",
"org/apache/xerces/parsers",
"org/apache/xerces/dom/events",
"org/apache/xerces/xs/datatypes",
"org/apache/xerces/impl/dv/dtd",
"org/apache/xerces/xni/grammars",
"org/apache/xerces/impl/dv/util",
"org/apache/xerces/dom",
"META-INF/maven/xerces",
"org/apache/xerces/impl/io",
"org/apache/xerces/dom3/as",
"org/apache/xerces/dom3",
"META-INF",
"org/apache/xerces/impl/xs/traversers",
"META-INF/maven",
"org/apache/xerces/xni",
"org/apache/xerces/impl",
"org/apache/xerces/impl/xs/util",
"META-INF/services",
"org/apache/xerces/xs",
"org/apache/xerces/xinclude",
"org/apache/xerces/impl/dv/xs",
"org/apache/xerces/jaxp/validation",
"org/apache",
"org/apache/xerces/impl/validation",
"org/apache/xml",
"org/apache/xerces/util",
"org/apache/xerces/stax/events",
"org/apache/xerces/impl/xs/identity",
"org/apache/xerces/impl/dtd",
"org/apache/wml/dom",
"org",
"org/apache/xerces/jaxp",
"org/apache/xerces/impl/xs/models",
"org/apache/xml/serialize",
"org/apache/xerces/impl/xpath",
"org/apache/xerces/impl/msg",
"org/apache/xerces/jaxp/datatype",
"org/apache/xerces",
"org/apache/xerces/impl/dtd/models",
"org/apache/xerces/impl/xs",
"org/apache/xerces/impl/xs/opti",
"org/apache/xerces/stax"
]
},
{
"type" => "org.jboss.modules.NativeLibraryResourceLoader",
"paths" => undefined
}
]
}
}
I have another server where deploying this war doesn't cause error.
I can compare them, but I can't see any difference.(in standalone.xml particulary).
The jar and main/module.xml are the same on two servers. The acl are identicals.
cat ~/modules/system/layers/base/org/apache/xerces/main/module.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2011, Red Hat, Inc., and individual contributors
~ as indicated by the #author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<module name="org.apache.xerces" xmlns="urn:jboss:module:1.8">
<resources>
<resource-root path="xercesImpl-2.12.0.SP02.jar"/>
</resources>
<dependencies>
<module name="jdk.xml.dom"/>
<module name="java.xml"/>
</dependencies>
</module>
ll ./modules/system/layers/base/org/apache/xerces/main/
total 1800
-rw-r--r-- 1 wildfly-flux wildfly-flux 1366 Jul 3 11:33 module.xml
-rw-r--r-- 1 wildfly-flux wildfly-flux 1835126 Jul 3 11:33 xercesImpl-2.12.0.SP02.jar
jar -tvf ./modules/system/layers/base/org/apache/xerces/main/xercesImpl-2.12.0.SP02.jar |grep SAX
...
2177 Fri Aug 24 11:10:24 CEST 2018 org/apache/xerces/parsers/SAXParser.class
...
9918 Fri Aug 24 11:10:26 CEST 2018 org/apache/xerces/jaxp/SAXParserImpl.class
...
I cannot edit code of the deploying war, I'm not the developer, but I can de-compile it.
I noticed the only reference about org.apache.xerces is:
package org.springframework.instrument.classloading;
...
/**
* ClassLoader decorator that shadows an enclosing ClassLoader,
* applying registered transformers to all affected classes.
...
public class ShadowingClassLoader extends DecoratingClassLoader {
/** Packages that are excluded by default */
public static final String[] DEFAULT_EXCLUDED_PACKAGES =
new String[] {"java.", "javax.", "sun.", "oracle.", "com.sun.", "com.ibm.", "COM.ibm.",
"org.w3c.", "org.xml.", "org.dom4j.", "org.eclipse", "org.aspectj.", "net.sf.cglib",
"org.springframework.cglib", "org.apache.xerces.", "org.apache.commons.logging."};
Does somebody can help ?
Where should I look to ?
I have re-install completely wildfly. The problem doesn't occur any more.

display source directories from sbt task for current project as well as source directories of project it dependsOn

sbt sourceDirectories
only displays source directories of current project, but doesn’t display source directories of projects that it depends using
dependsOn(ProjectRef)
Below is the simplified task.
lazy val showAllSourceDirs = taskKey[Unit]("show source directories of all projects")
showAllSourceDirs := {
val projectRefs = loadedBuild.value.allProjectRefs.map(_._1)
projectRefs foreach { projectRef =>
/*
Below line is giving IllegalArgumentException exception :-
[error] java.lang.IllegalArgumentException: Could not find proxy for projectRef: sbt.ProjectRef in
List(value projectRef, value $anonfun, method sbtdef$1, method $sbtdef, object $7fb70afe92bc9a6fedc3,
package <empty>, package <root>) (currentOwner= method $sbtdef )
*/
val sources = (projectRef / Compile / sourceDirectories).value
sources.foreach( println )
}
}
Link for simplified project to reproduce problem :-
https://github.com/moglideveloper/Example
Steps :

Go to ApiSpec directory from command line and run below command :-
sbt showAllSourceDirs
Expected output : print all source directories of Api and ApiSpec project
Actual output : throws java.lang.IllegalArgumentException
I believe you cannot do that, because sbt works with macros. What you can do here, is adding sourceDirectories of Api into sourceDirectories of ApiSpec. This means, that if you add the following into your sbt:
Compile / sourceDirectories ++= (apiModule / Compile / sourceDirectories).value
Then, when running:
sbt sourceDirectories
You get the output:
[info] * /workspace/games/Example/ApiSpec/src/main/scala-2.12
[info] * /workspace/games/Example/ApiSpec/src/main/scala
[info] * /workspace/games/Example/ApiSpec/src/main/java
[info] * /workspace/games/Example/ApiSpec/target/scala-2.12/src_managed/main
[info] * /workspace/games/Example/Api/src/main/scala-2.12
[info] * /workspace/games/Example/Api/src/main/scala
[info] * /workspace/games/Example/Api/src/main/java
[info] * /workspace/games/Example/Api/target/scala-2.12/src_managed/main
There is one thing you need to notice - you are overriding the current sourceDirectories, so be sure you are not using it anywhere else.
Another note, is that you need to add this line on every dependency you have. So I am not sure how big is your project, and how feasible that is.
If you'd like to have a different task, you can do that, bur use the modules themselves, and not thru reflection, again due to macros.
lazy val showAllSourceDirs = taskKey[Unit]("show source directories of all projects")
showAllSourceDirs := {
println((apiSpecProject / Compile / sourceDirectories).value)
println((apiModule / Compile / sourceDirectories).value)
}

React Native Map Box Execution Failed transform classes with Dex / JarMerging

I've just started using MapBox in react-native but I appear to be getting the following error
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
Enabling multidex with
multiDexEnabled true
I then get the following
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/internal/ws/RealWebSocket$1.class
Here's the config
build.gradle .../android
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
// Add jitpack repository (added by tipsi-stripe)
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
}
build.gradle ../app
dependencies {
compile project(':mapbox-react-native-mapbox-gl')
compile project(':react-native-branch')
compile project(':react-native-camera')
compile project(':tipsi-stripe')
compile project(':react-native-device-info')
compile project(':react-native-vector-icons')
compile project(':react-native-i18n')
compile project(':react-native-geocoder')
compile project(':react-native-fbsdk')
compile(project(':react-native-maps')) {
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:25.0.0"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.google.android.gms:play-services-base:11.+'
compile 'com.google.android.gms:play-services-maps:11.+'
}
settings.gradle
include ':mapbox-react-native-mapbox-gl'
project(':mapbox-react-native-mapbox-gl').projectDir = new File(rootProject.projectDir, '../node_modules/#mapbox/react-native-mapbox-gl/android/rctmgl')
include ':react-native-branch'
project(':react-native-branch').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-branch/android')
include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':tipsi-stripe'
project(':tipsi-stripe').projectDir = new File(rootProject.projectDir, '../node_modules/tipsi-stripe/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-i18n'
project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android')
include ':react-native-geocoder'
project(':react-native-geocoder').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-geocoder/android')
include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
include ':app'
MainApplication.java
import android.app.Application;
import android.content.Intent;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.react.ReactApplication;
import com.mapbox.rctmgl.RCTMGLPackage;
import io.branch.rnbranch.RNBranchPackage;
import io.branch.referral.Branch;
import com.lwansbrough.RCTCamera.RCTCameraPackage;
import com.gettipsi.stripe.StripeReactPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.oblador.vectoricons.VectorIconsPackage;
import com.i18n.reactnativei18n.ReactNativeI18n;
import com.devfd.RNGeocoder.RNGeocoderPackage;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.airbnb.android.react.maps.MapsPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RCTMGLPackage(),
new RNBranchPackage(),
new RCTCameraPackage(),
new StripeReactPackage(),
new RNDeviceInfo(),
new MapsPackage(),
new VectorIconsPackage(),
new ReactNativeI18n(),
new RNGeocoderPackage(),
new FBSDKPackage(mCallbackManager)
);
}
};
#Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
#Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
SoLoader.init(this, /* native exopackage */ false);
// initialize the Branch object
Branch.setPlayStoreReferrerCheckTimeout(0);
Branch.getAutoInstance(this);
}
}
Stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lokhttp3/internal/ws/WebSocketReader;
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lokhttp3/internal/ws/WebSocketReader;
at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more
Caused by: com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lokhttp3/internal/ws/WebSocketReader;
at com.android.build.gradle.internal.transforms.DexMergerTransform.transform(DexMergerTransform.java:230)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
... 39 more
Caused by: com.android.dex.DexException: Multiple dex files define Lokhttp3/internal/ws/WebSocketReader;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
148 actionable tasks: 4 executed, 144 up-to-date
I'm not sure if this is a matter of my current project config or what not, but i've not seen reports of this so far.
Update with adding in workaround enables app to launch but then another issue arises: NoClassDefFoundError: com.google.android.gms.wallet.MaskedWalletRequest
I've now added in configurations.all { resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.4.1' } as suggested by https://github.com/facebook/react-native/issues/12646 which enables the app to build succesfully but then there is an issue of NoClassDefFoundError: com.google.android.gms.wallet.MaskedWalletRequest
Just to clarify moving over to mapbox, I'll no longer need react-native-maps, and the reason for the move over is the greater level of detail i.e. in the buildings.
Thanks, appreciate you're help
Looks like a similar issue was raised against the repo and can probably be resolved if you...
exclude android.arch.core module from the mapbox project
compile 'com.google.android.gms:play-services-base:11.+'
compile 'com.google.android.gms:play-services-maps:11.+`
Version for com.google.android.gms:play-services should be same in build.gradle for app. and and in build.gradle of your packages installed.
-Here 11.+ version refers to any version greater then 11 which currently
available.i would suggest to make this version static and copy that version in build.gradle of your package in node-modules which gives error.
it is necessary to have same com.google.android.gms:play-services version throughout the app
Thankfully I was finally able to get mapbox in on my android version in react-native after resolving issues that popped up along the way: First of all my first attempt was on an older version of react-native 0.44.0, I later upgraded to the latest version of react native
"react-native": "^0.50.3",
and using react
"react": "^16.1.1",
Error
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
This was the first, the app exceeds the maximum number of methods so we go ahead and enable multiDex in app/gradle
android {
compileSdkVersion 25
defaultConfig {
...
multiDexEnabled true
The next issue was
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/internal/ws/RealWebSocket$1.class
One approach to resolving this was found to use on the older version of react-native but this was not required it seems on the most recent version following the upgrade with react-native-git-upgrade
configurations.all { resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.4.1' }
Another issue that popped up was
Failed to resolve: android.arch.lifecycle:extension:1.0.0-alpha3
which was resolved by adding maven { url 'https://maven.google.com' } to
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.google.com' }
}
}
Then there was an Aapt exception error which was resolved by adding to gradle.properties
android.enableAapt2=false
The app would now build succesfully but on starting irrespective of whether upraded to the latest version or not would show the error
C++ Exception in 'NativeModules': java.lang.NoClassDefFoundError: com.google.android.gms.wallet.MaskedWalletRequest
which was resolved by adding
implementation 'com.google.android.gms:play-services-wallet:11.+'
to our gradle dependencies.
And then the app built and started succesfully with no errors.
I think upgrading to the latest version of react-native, react, helped a great deal with compatability, speed, and performance, as well as by using the latest version of gradle and for example when doing so
configurations.all { resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.4.1' }
was needed to be added assuming that conflict must have been resolved in a later version.
Anyway, hope this helps someone, and pleased to say I've finally got mapbox in the app.
Thanks to #nitaliano for helping out over at https://github.com/mapbox/react-native-mapbox-gl/issues/785, and providing guidance, a long with the references and help found on https://github.com/tipsi/tipsi-stripe/issues/18 https://github.com/facebook/react-native/issues/12646 https://github.com/mapbox/react-native-mapbox-gl/issues/767 and also the help from Chris Geirman and Rajat Gupta here.
The following references were also helpful
https://facebook.github.io/react-native/docs/upgrading.html
https://reactjs.org/blog/2017/04/07/react-v15.5.0.html
https://reactjs.org/blog/2017/09/26/react-v16.0.html
https://github.com/mlaursen/react-md/issues/325
https://www.npmjs.com/package/prop-types
https://github.com/mapbox/react-native-mapbox-gl/blob/master/example/src/App.js
https://github.com/mapbox/react-native-mapbox-gl/blob/master/example/src/components/ShowMap.js
Mapbox: Cant add LocationLayer plugin in gradle
https://github.com/tipsi/tipsi-stripe/issues/18
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
Thanks again 👍

Using scala-js-env-selenium for crossbrowser testing

I am using https://github.com/scala-js/scala-js-env-selenium for in-browser testing, so far tests are running fine in local browser. Now i want to run my tests in remote browsers (https://app.crossbrowsertesting.com)
I created new CrossBrowser
import org.openqa.selenium.remote.{DesiredCapabilities, RemoteWebDriver}
import org.scalajs.jsenv.selenium.{BrowserDriver, SeleniumBrowser}
import java.net.URL
object CrossBrowser {
def apply(): CrossBrowser = new CrossBrowser
val username = "email"
// Your username
val authkey = "xxxxxxxxxx" // Your authkey
}
class CrossBrowser private() extends SeleniumBrowser {
def name: String = "RemoteBrowser"
def newDriver: BrowserDriver = new CrossDriver
private class CrossDriver extends BrowserDriver {
protected def newDriver(): RemoteWebDriver = {
val caps = new DesiredCapabilities()
caps.setCapability("name", "Selenium Test Example")
caps.setCapability("build", "1.0")
caps.setCapability("browser_api_name", "IE10")
caps.setCapability("os_api_name", "Win7x64-C2")
caps.setCapability("screen_resolution", "1024x768")
caps.setCapability("record_video", "true")
caps.setCapability("record_network", "true")
new RemoteWebDriver(new URL("http://" + CrossBrowser.username + ":" + CrossBrowser.authkey + "#hub.crossbrowsertesting.com:80/wd/hub"), caps)
}
}
}
and updated build settings
jsEnv := new org.scalajs.jsenv.selenium.SeleniumJSEnv(CrossBrowser()),
jsEnv in Test := new org.scalajs.jsenv.selenium.SeleniumJSEnv(CrossBrowser())
when i ran test command i got following output
[trace] Stack trace suppressed: run last client/test:loadedTestFrameworks for the full output.
[error] (client/test:loadedTestFrameworks) org.openqa.selenium.WebDriverException: [fc92901a-f56a-4e4b-9d75-953402cbfe35] Test has timed out after 199 seconds
[error] Command duration or timeout: 199.20 seconds
[error] Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
[error] System info: host: 'Chandras-MacBook-Pro.local', ip: 'xx.xx.xxx.x', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.3', java.version: '1.8.0_25'
[error] Driver info: org.openqa.selenium.remote.RemoteWebDriver
[error] Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=10, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, webdriver.remote.sessionid=fc92901a-f56a-4e4b-9d75-953402cbfe35, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:33793/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
[error] Session ID: fc92901a-f56a-4e4b-9d75-953402cbfe35
Reason for time out is , test-runner tried to load file:/var/folders/n0/c0fyqlqx0gg15mv4t5mchgj80000gn/T/1464125278337-0/scalajsRun.html on remote machine which doesn't exist.
is it possible to do this kind of testing ..?(copy files to some server and load that url ..)
Selenium will need access to your files if you are running local tests. That's usually done via proxies. There seems to be support for local testing though (https://crossbrowsertesting.com/local-testing), you could try to contact them to set this up.

Spark program behave differently based on --master is set to local[4] or yarn-client

I am using the movielens dataset to load Movie information into a spark program and print the same using the following code snippet
import org.apache.spark.{SparkConf, SparkContext}
object MovieApp {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("movie-recommender")
val sc = new SparkContext(conf)
val movieFile = "/mnt/DATASETS/ml-1m/movies.dat"
val movieData = sc.textFile(movieFile)
val movies = movieData.map(_.split("::") match { case Array(movieid, title, genres) =>
val genreList = genres.split("|")
(movieid, title, genreList)
})
println("Num movies:" + movies.count())
movies.foreach { case movielist =>
println("ID:" + movielist._1 + "Title:" + movielist._2)
}
}
}
When I run the code using the command
spark-submit --master local[4] --class "MovieApp" movie-recommender.jar I get the expected output as
*root#philli ml]# /usr/lib/spark/bin/spark-submit --master local[4] --class "MovieApp" movie-recommender_2.10-1.0.jar
14/12/05 00:17:37 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Num movies:3883
ID:2020 Title:Dangerous Liaisons (1988)
ID:2021 Title:Dune (1984)
ID:2022 Title:Last Temptation of Christ, The (1988)
ID:2023 Title:Godfather: Part III, The (1990)
ID:2024 Title:Rapture, The (1991)
ID:2025 Title:Lolita (1997)
ID:2026 Title:Disturbing Behavior (1998)
ID:2027 Title:Mafia! (1998)
ID:2028 Title:Saving Private Ryan (1998)
ID:2029 Title:Billy's Hollywood Screen Kiss (1997)
...
*
but when I run the same on a hadoop cluster using the command
spark-submit --master yarn-client --class "MovieApp" movie-recommender.jar the output is different as below (no movie details???)
*[root#philli ml]# /usr/lib/spark/bin/spark-submit --master yarn-client --class "MovieApp" movie-recommender_2.10-1.0.jar
14/12/05 00:21:05 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/12/05 00:21:07 WARN BlockReaderLocal: The short-circuit local reads feature cannot be used because libhadoop cannot be loaded.
--args is deprecated. Use --arg instead.
Num movies:3883
[root#philli ml]# *
Why should the behavior of the program change between running it as local vs on the cluster....I have built spark-1.1.1 for hadoop using the command
mvn -Pyarn -Phadoop-2.4 -Dhadoop.version=2.4.0 -DskipTests clean
package
The cluster I am using is HDP2.1
Sample movies.dat file is as follows:
1::Toy Story (1995)::Animation|Children's|Comedy
2::Jumanji (1995)::Adventure|Children's|Fantasy
3::Grumpier Old Men (1995)::Comedy|Romance
4::Waiting to Exhale (1995)::Comedy|Drama
5::Father of the Bride Part II (1995)::Comedy
6::Heat (1995)::Action|Crime|Thriller
7::Sabrina (1995)::Comedy|Romance
8::Tom and Huck (1995)::Adventure|Children's
9::Sudden Death (1995)::Action
10::GoldenEye (1995)::Action|Adventure|Thriller
When you run the program on a cluster, the foreach closure will be executed in the workers, therefore the println is happening, but on the worker's stdout and not on the driver.
Look into the yarn logs and you will find the expected output.