Importing missing package (sun.security.pkcs.PKCS10) automatically in Android Studio - java

I have to use PKCS10 class into my project. I tried to import sun.security.pkcs.PKCS10; into my activity code but studio shows "Cannot resolve symbol PKCS10" at both places where I have imported it and where I want to instantiat it.
Note: I haven't added any dependency or library (like .jar) to my project.
I want to know whether can it be automatically?

The class sun.security.pkcs10.PKCS10 was removed from the JDK. Using a class that was internal and already removed from the JDK is going a step beyond just using an internal API.
Put this into your build.gradle file.
compileJava {
options.forkOptions.javaHome = file(System.properties['java.home'])
}
And if this does not work, put this into you build.gradle(app) dependencies.
compile group: 'com.sun', name: 'rt', version: '1.5.0_06'

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 ...

BodyEditorLoader.jar gives NoSuchMethodError

I was just starting to use the BodyEditorLoader.jar library but i got a NoSuchMethodError without any reason. Then i googled it and found a post on stackoverflow which wasn't useful and links were also broken but i came to know that the official library out there is buggy.
How do i fix this? Could not found the updated version of the library. Also some people provided the updated java file but how do i make it a library file as the library file contains the .class file and not the .java file.
Anyways here is the error:
java.lang.NoSuchMethodError: com.badlogic.gdx.utils.JsonReader.parse
and here is the code that gives the error:
BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("data/test.json"));
From question it's seems you have some buggy BodyEditorLoader class, you can inject gdx-utils jar inside your core module and after that you can access BodyEditorLoader class inside your project, May be it solve your problem.
dependencies {
compile group: 'com.github.itsabhiaryan', name: 'gdx-utils', version: '1.0.1-SNAPSHOT'
}
Don't forget to refresh all of your gradle module.

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.

Adding .java library to an Android project

I have a library I want to add to my Android Application. But the problem is that the library is separated into .java files. Now I have tried to add a module to do the job but it does not work. My problem is I do not know how to add a bunch of .java files to my Android project to use throughout my app. I am new to Android dev and I have looked around but cannot find a clear explanation of how to add my type of library to an Android project.
I can see a couple of problems in the screenshot that you just posted above.
1) It seems that you're not telling Gradle (and therefore Android Studio) that you have Java files that need to be compiled. You can fix that by adding this to the build.gradle of the TMDB-Lib module:
sourceSets {
main {
java {
srcDir 'libs'
}
}
}
and then adding the module to your settings.gradle.
2) It seems that the Tmdb classes don't have a package (i.e. their first line isn't a package declaration) so the right way to import them into your Java code is by using just their class name:
import TmdbApi;
instead of:
import TMDB-lib.libs.TmdbApi;

Categories