Add .jar to dependencies in React Native - java

I am quite new to React Native but I need to create an Android Module for the Honeywell CT50 barcode scanner.
I have created a libs folder in MyApp/android/app as stated in these two SO posts:
Post 1
Post 2
The second post says I must then add the package name to the dependencies something like this:
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile 'com.facebook.react:react-native:0.19.+'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
}
This the part I am struggling with, the formatting of the name. Here's what the contents of the .jar file looks like:
I would like to reference the AidcManager to do this I have tried:
compile "com.honeywell.aidc.AidcManager"
compile "com.honeywell.aidc:AidcManager"
compile "com.honeywell.aidc:"
Each time I get an error during my build saying something like:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.honeywell.aidc:AidcManager:.
Searched in the following locations:
file:/Users/XXX/.m2/repository/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/Users/XXX/.m2/repository/com/honeywell/aidc/AidcManager//AidcManager-.jar
https://jcenter.bintray.com/com/honeywell/aidc/AidcManager//AidcManager-.pom
https://jcenter.bintray.com/com/honeywell/aidc/AidcManager//AidcManager-.jar
file:/XXX/node_modules/react-native/android/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/XXX/node_modules/react-native/android/com/honeywell/aidc/AidcManager//AidcManager-.jar
file:/Users/XXX/Library/Android/sdk/extras/android/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/Users/XXX/Library/Android/sdk/extras/android/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.jar
file:/Users/XXX/Library/Android/sdk/extras/google/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.pom
file:/Users/XXX/Library/Android/sdk/extras/google/m2repository/com/honeywell/aidc/AidcManager//AidcManager-.jar
Required by:
MyApp:app:unspecified
Can anyone point me in the right direction? Many thanks in advance.

Just copy .jar files in libs folder and import classes or packages from it in your .java file. There is no need to reference them in .gradle file.

Answering wayyyyyyy to late, but might be helpful to others who are looking for this answer,
just add .jar in libs, then add below into gradle
implementation files('libs/<YourJarName>.jar')
Or
Right click the jar and select "Add jar to project" option

Related

Gradle Dependencies

I'm trying to use JSON Simple to parse a JSON file into Java in a Gradle JavaFX project.
I've tried a few things:
Adding implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' to the build.gradle file. ... Won't let me do import org.json.simple.JSONParser;
Error: error: package org.json.simple does not exist
Adding implementation 'com.googlecode.json-simple:json-simple:1.1.1' to the build.gradle file. ... gives same error as above.
In IntelliJ, I've tried manually downloading and adding the jar file:
First I added a new directory to the root called 'libs' and added the jar file there. Went to File > Project Structure > Libraries > '+' > Java, selected the file and pressed the module I wanted to add it to. Then I added requires json.simple; into the module-info.java file.
IntelliJ does not come up with any errors, but when I do gradle run, it comes up with an error in the modules-info.java file that says error: module not found: json.simple
I have no idea why that last error is happening, I made sure the module was applied to the root as well (Where the modules-info.java file is.
I've tried gradle clean, invalidating caches and removing caches altogether.
If anyone knows why this issue is occuring (or can suggest another way I can parse a JSON file), that would be great!
Thanks in advance.

More than one library with package name 'com.google.android.gms.license'

I'm using angular 4 and ionic 3. Now when i run "ionic cordova run android"
It gives me the following error:
"more than one library with package name 'com.google.android.gms.license'"
My project.property file:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.android.support:support-v4:27.1.0
cordova.system.library.2=com.android.support:support-v4:27.1.0
cordova.system.library.3=com.android.support:support-v4:27.1.0
cordova.system.library.4=com.android.support:appcompat-v7:25.+
cordova.gradle.include.1=cordova-plugin-firebase/starter-build.gradle
cordova.system.library.5=com.google.gms:google-services:+
cordova.system.library.6=com.google.android.gms:play-services-tagmanager:+
cordova.system.library.7=com.google.firebase:firebase-core:+
cordova.system.library.8=com.google.firebase:firebase-messaging:+
cordova.system.library.9=com.google.firebase:firebase-crash:+
cordova.system.library.10=com.google.firebase:firebase-config:+
My dependencies in build.gradle file :
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.android.support:support-v4:27.1.0"
compile "com.android.support:appcompat-v7:25.+"
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
compile "com.google.firebase:firebase-core:+"
compile "com.google.firebase:firebase-messaging:+"
compile "com.google.firebase:firebase-crash:+"
compile "com.google.firebase:firebase-config:+"
// SUB-PROJECT DEPENDENCIES END
}
Thanks in advance :)
Please update your build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
changes your version to 2.3.0
its worked for me...
Thanks
Change your project.property file to:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.android.support:support-v4:27.1.0
cordova.system.library.2=com.android.support:support-v4:25.+
cordova.system.library.3=com.android.support:appcompat-v7:25.+
cordova.system.library.6=com.google.firebase:firebase-core:11.8.0
cordova.system.library.7=com.google.firebase:firebase-messaging:11.8.0
cordova.system.library.8=com.google.firebase:firebase-crash:11.8.0
cordova.system.library.9=com.google.firebase:firebase-config:11.8.0
cordova.system.library.9=com.google.firebase:firebase-auth:11.8.0
cordova.system.library.9=me.leolin:ShortcutBadger:1.1.4#aar
I think your issue comes here:
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
Rather than importing gms services like this, you should only import specific libraries.
You are using together those both library.
compile "com.google.gms:google-services:+"
compile "com.google.android.gms:play-services-tagmanager:+"
this "com.google.gms:google-services:+" library has all play service libraries.
Remove this dependency "com.google.android.gms:play-services-tagmanager:+" and it will work.
But still This is not a good way to add com.google.gms:google-services:+, because un-necessary you are adding all google's dependency.
Instead of this dependecy you can use specific dependency, for example if you are using map, then use only map play service.
Here is the list of all play service dependency https://developers.google.com/android/guides/setup .
I suggest you add only required dependency instead of play service universal dependency.
If you've already changed version at /android/build.gradle but not work yet. Maybe you need check some library package at node_modules.
Eg: react-native-onesignal also compile some play-services with highest version (they use +) so it can make this issue.
You can put a script at root directory and add {"scripts": {"postinstall": "node changeVersionGoogleService.js"}} in package .json so it can run to auto change your version when you npm install.
This is the script: https://gist.github.com/duytq94/47ef945131b61de538447d449813b3d4
My script at now auto change 'react-native-onesignal',
'react-native-admob',
'react-native-maps',
'react-native-google-sign-in'
None of the solutions discussed here worked for me so I went on to
renamed the /platform/android folder and Remove android platform
add android platform ionic cordova platform add android
faced another issue with facebook due to this which has a solution here where you need to add your app id and name in platforms/android/app/src/main/res/values/strings.xml file
compiled worked fine after that.
The problem occurred for me when upgrading to cordova 7.
just Add :
googlePlayServicesVersion=11.8.0
to your gradle.properties
have fun ...

Gradle Transitive Dependencies from Modules

Disclaimer:
I'm new to Gradle, have read a lot of docs, and I don't know whether my maven-style understanding is tripping me out, or whether it's the sleep dep (kids - don't ask), but I'm still not getting it.
Problem Background:
I have a project that consists of several modules.
One of the modules, let's call it data-structure defines a data structure
Another module, data-structure-fabsearch, defines an implementation for a data source for the data structure, and finally
A third module, fabsearch-common, defines some common data source classes (eg: connection management to a fabsearch data source etc).
The reason I've done it like this is because there's actually another module that also uses the fabsearch-common stuff.
Anyway, my data-structure-fabsearch build.gradle looks something like this:
dependencies {
compile project(:data-structure)
compile project(:fabsearch-common)
}
The fabsearch-common module declares depedencies for the fabsearch api (let's call it fabsearch-api-1.0.0).
So, the dependency tree for data-structure-fabsearch should look like this:
- data-structure-fabsearch
- data-structure
- fabsearch-common
- fabsearch-api-1.0.0
This was all working wonderfully last night. This morning I came to work and all of a sudden those dependencies don't resolve anymore. References to fabsearch-api-1.0.0 classes are no longer found.
What I've Tried
1. In the parent build.gradle:
project(':data-structure-fabsearch'){
apply plugin: 'java'
dependencies {
compile project(path: ':data-structure', configuration: 'compile')
compile project(path: ':fabsearch-common', configuration: 'compile')
}
}
I've tried this with and without the configuration setting.
2. In the data-structure-fabsearch build.gradle file, adding the configuration parameter.
3. Restarting IntelliJ
4. Clicking the refresh icon in the Gradle tool window (repeatedly)
5. Reading all about transitive dependencies in the Gradle user guides
6. Drinking tea (repeatedly)
None of the above work.
What I'm Expecting
I'm expecting that the fabsearch-common dependencies (the fabsearch-api jars) should also be included in the data-structure-fabsearch dependency tree. All references to fabsearch-api classes in data-structure-fabsearch should resolve etc etc.
My Question[s]
Whilst this is possible in Maven, is it possible in Gradle?
What do I have to do to get it to work?
How much sleep dep can you take without dying?
Many thanks for any help.
Turns out the problem wasn't gradle at all. The problem was IntelliJ.
It got it's knickers into a proper twist!
Solution:
1. Close the project in IntelliJ
2. Delete the .idea directory
3. Delete all .iml files and any other IntelliJ cra-useful files
4. Open project in IntelliJ, choose same directory. Problem disappears.

how to fix build.gradle for map application on android

I am developing a basic map example but I'm in trouble with android studio.
I got this error :
Error:(9, 0) Cause: startup failed:build file 'C:\Users\Tugrul\AndroidStudioProjects\ServiceTextSender\build.gradle': 9: expecting '}', found ':' # line 9, column 31.
compile ‘com.android.support:appcompat-v7:+’1 error
And here an error resource from my build.gradle file(dependencies :
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
compile ‘com.android.support:appcompat-v7:+’
compile ‘com.google.android.gms:play-services:3.1.36′
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
How can I fix this? Could you help me please? I'm in trouble with Android Studio. I'm in trouble with this error.
Regarding the error:
Looks like you are adding this to the wrong gradle file, should be added to the app's gradle file (the one in the app's folder), not the module (the top one). The top one specifies the gradle plugin to use and as you have it listed here, I'm assuming you are editing the wrong build-gradle file.
If you instead check in the same directory that contains the src-folder (not inside src) you will find the app's dependencies section where you can add that line.
And/Or you are just using the wrong characters should be ' and not ‘.
Suggested easier solution:
Create a new Google Map Activity using the template when starting a new project, or right click in your project package and choose (in the popup menu):
New -> Google -> Google Maps Activity
And everything will be set up for you.
I think your problem is character error. ' and ‘ are different.
Try change this :
classpath 'com.android.tools.build:gradle:1.3.0'
compile ‘com.android.support:appcompat-v7:+’
compile ‘com.google.android.gms:play-services:3.1.36′
to this
classpath 'com.android.tools.build:gradle:1.3.0'
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:3.1.36'
Edit:
These are gradle Files:
You need to add your
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:3.1.36'
}
lines to Module Specific build.gradle file shown as above.

Dynamically add JAR to Gradle dependencies

Currently, my build.gradle has a dependency on an external library built with Ant. To accomplish building the library, I followed the advice here and created a task which builds the external library, and copies it to the libs/ folder.
The task is called as part of a dependency:
build.gradle
dependencies {
compile fileTree('libs') {
include '*.jar'
builtBy 'myTask'
}
}
task myTask (type: GradleBuild) { GradleBuild antBuild ->
antBuild.buildFile('external-stub.gradle')
antBuild.tasks = ['clean', 'ivy.check', 'ivy.download', 'ivy.task', 'ivy',
'init', 'mergeCode', 'compile', 'jar', 'copyJarsToProject']
}
However, when the compile actually runs, the library I just built and copied in is not included in the dependencies, as evidenced by a whole lot of compilation errors.
Am I including the library the wrong way?
The full build.gradle and associated files are over at Github, and I've linked to the specific commit I'm having issues with: Source Repository
Alright, took me a while to get a build I was happy with. But, here's what was changed.
The actual build of the JAR was built using the same style, but moved to the external project (so that the main build project wasn't reaching across to it). I'll give an in-depth explanation below, but the commits are here and here. These are in order.
Basically, we export the jar as an artifact that other projects can depend on, rather than copying over the Jar ourselves. This way, the Ant build runs and other projects can see the Jar we just created. This is the end of the first commit. In the second commit, the task outputs are marked as needing to be regenerated only if the Jar does not exist. This was due to the fact that whenever I tried to build the app, it would take minutes to regen the Jar, and then have to repackage everything else as well. The code is below:
build.gradle External Project
configurations {
buildJSword
}
task doBuildJSword (type: GradleBuild) {
buildFile = 'jsword-stub.gradle'
tasks = ['clean', 'ivy.check', 'ivy.download', 'ivy.task', 'ivy',
'init', 'mergeCode', 'compile', 'jar'] //, 'copyJarsToMinimalBible']
ext.outputJar = file('distribution/jsword.jar')
outputs.upToDateWhen {
ext.outputJar.exists()
}
}
artifacts {
buildJSword(doBuildJSword.ext.outputJar) {
builtBy doBuildJSword
}
}
Then, the main project just has to add this project as a compile-time dependency:
build.gradle Main Project
compile project(path: ':jsword-minimalbible', configuration: 'buildJSword')
Hope this is helpful for anyone with a similar issue, let me know if you have questions!
Note: The build currently does not clean itself properly, so if you change any code in the external project, you need to delete the external Jar for everything to regenerate itself correctly.

Categories