I am trying to break parts of my app out into a reusable module.
Now, a class in my module that is trying to import android.bluetooth.BluetoothDevice cannot resolve the symbol.
Here is my gradle script for the module:
apply plugin: 'java'
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile files('libs/Android_Platform_Adapter.jar')
compile files('libs/wisepadapi-android-2.7.0.jar')
compile files('libs/emvswipeapi-android-2.12.3.jar')
}
This is the first module I've worked on. I'm sure it's something easy. Thanks!
Here is the mismatch. You are trying to import import android.bluetooth.BluetoothDevice inside a strictly java module (apply plugin: 'java').
You should create android library module. Create a new Phone & Tablet module as described here.
Related
After creating class for unit tests like in official documentation I imported com.google.common.truth.Truth.assertThat and org.junit.Test libraries, but android studio can't pick it up and shows errors "Cannot resolve symbol "Truth"" and "Cannot resolve symbol "Test"".
After searching the ways to solve this problem I came across a question on StackOverflow that asked similar thing. I did all the things that were recommended over there but I still can't import those classes.
My project build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
My project module build.gradle
dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.google.truth:truth:1.1.3'
}
My test class
import com.google.common.truth.Truth.assertThat;
import org.junit.Test;
Android gradle plugin requires java 11 to run.
Please change gradle java plugin to 11 like below screenshot.
So I've tried adding Firebase dependency to my gradle project. But it doesn't seem to be working. It adds fine, there's no errors or anything and I can see the firebase jar in my Referenced Libraries. But whenever I try to import anything from it like import google.com.firebase, it doesn't show up. What am I doing wrong? These are the only imports I'm seeing.
This is my repositories thing in build.gradle
repositories {
mavenCentral()
google()
jcenter()
}
This is my dependencies thing
dependencies {
compile 'com.google.firebase:firebase-database:19.3.1'
}
So basically, the dependency adds correctly I think, it does show up on the Referenced libraries on my IDE but I don't know why I cannot access it?
Btw I'm not making an Android app, it's a mod for minecraft that uses forge gradle.
Also this is my gradle version: https://services.gradle.org/distributions/gradle-4.1-all.zip
It was because i used an dependency meant for android developers with the aar extensions so instead of using
compile 'com.google.firebase:firebase-database:19.3.1'
In dependencies in build.gradle using this which is meant for the java thing works now.
compile 'com.google.firebase:firebase-admin:6.16.0'
I am trying to compile other developer's open source custom library.
I have compiled or find dependencies but it fails to build in gradle
which was failing to import java's internal library package org.objectweb.asm
it's a java internal library so it must be in tools.jar but build.properties it's aleady importing java's tools.jar and aleady applying plugin java so i have no idea
here it's build.properties ( main part)
allprojects {
apply plugin: 'java'
group 'com.nemosw.spigot'
version '1.2.21'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
javadoc.options.encoding = 'UTF-8'
repositories {
// junit
mavenCentral()
// nms spigot & mox
mavenLocal()
}
}
project(':core') {
processResources {
filesMatching('**/*.yml') {
expand project.properties
}
}
repositories {
maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots/' }
flatDir { dirs 'libs' }
}
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compileOnly files(Jvm.current().toolsJar)
compile 'com.nemosw.mox:mox-collections:1.0'
compile 'com.nemosw.mox:mox-task:1.0'
compile 'com.nemosw.mox:mox-math:1.0.2'
compile 'com.nemosw.mox:mox-tools:1.1'
}
}
other part's are can be found in here:
https://github.com/nemosrc/tap
also you need to fix some dependencies and compile he's mox library(all of them)
https://github.com/nemosrc/mox-math
https://github.com/nemosrc/mox-tools
https://github.com/nemosrc/mox-collections
https://github.com/nemosrc/mox-task
and tons of error because of the failed library.
C:\tap\core\src\main\java\com\nemosw\spigot\tap\event\ASMEntityEventExecutor.java:6:
error: package org.objectweb.asm does not exist import
org.objectweb.asm.ClassWriter;
^
C:\tap\core\src\main\java\com\nemosw\spigot\tap\event\ASMEntityEventExecutor.java:7:
error: package org.objectweb.asm does not exist import
org.objectweb.asm.MethodVisitor;
^
C:\tap\core\src\main\java\com\nemosw\spigot\tap\event\ASMEntityEventExecutor.java:8:
error: package org.objectweb.asm does not exist import
org.objectweb.asm.Type;
^
C:\tap\core\src\main\java\com\nemosw\spigot\tap\event\ASMEntityEventExecutor.java:15:
error: package org.objectweb.asm does not exist import static
org.objectweb.asm.Opcodes.*;
^
C:\tap\core\src\main\java\com\nemosw\spigot\tap\event\ASMEventExecutor.java:9:
error: package org.objectweb.asm does not exist import
org.objectweb.asm.ClassWriter;
You can add dependency in dependencies block -
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
compileOnly files(Jvm.current().toolsJar)
compile 'com.nemosw.mox:mox-collections:1.0'
compile 'com.nemosw.mox:mox-task:1.0'
compile 'com.nemosw.mox:mox-math:1.0.2'
compile 'com.nemosw.mox:mox-tools:1.1'
compile 'org.ow2.asm:asm:'7.1'
}
You can find more dependency from this site
https://mvnrepository.com/
Why would you think that it's a Java internal library?
The org.objectweb.asm package is part of the ASM library: https://asm.ow2.io/
You might want to add this to your Gradle build:
compile group: 'org.ow2.asm', name: 'asm', version: '7.1'
For some internal APIs, this is a limitation in javac.
You can use this property with javac to make it work
javac -XDignore.symbol.file=true
From Java 9 onwards you can use
javac --add-exports java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED
Using Java 9+?
Create a file called module-info.java
module com.example.nightmare {
requires org.objectweb.asm;
}
place in root of jar or maybe 'java/main/src/resources'
(your amount of effort or results may vary and will likely need a bunch more requires)
It's an internal class for use by JVM components which may have unexpected changes not only between versions, but unscheduled in patches, so use at your own peril. The recommended approach loads a version from a jar separate from one used by the JVM. I'll surmise keeping it 'internal' adds to the stability in development of the OpenJdk and on the bleeding edge deployments. Any use of such internal components is never recommended.
Of course lots of things are not recommended that we still do. Enjoy!
I am getting this error when using an import method I found to Android Studio.
https://github.com/MagicMicky/FreemiumLibrary/wiki/Import-the-library-in-Android-Studio
The import method I am using is in the above link.
This is the error message (Click Here)
This is how it is in the settings.gradle
include ':app',':lib:json-simple-master'
and this is how I edited the build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
compile project(':lib:json-simple-master')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
This is how I am trying to import the file
import org.json.simple.*;
You shouldn't need to follow those instructions
But you edited the wrong build.gradle file.
Update the one like this
android {
...
}
dependencies {
...
compile group: 'com.magicmicky.freemiumlibrary', name: 'library', version: '1.1'
}
If you want a JSON library, android already has org.json... If you want Java object deserialization, use Jackson or Gson.
json-simple doesn't seem necessary in an app
I have set up an app engine backend in my Android project using Android Studio successfully by following the hello world guide here. The app can communicate with the backend server. My next step is code the backend such that it can send emails. I am following the official guide here. However, I am facing an issue with the following import statements, which cannot be resolved.
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
I am really puzzled why this is the case as the guide specifically says "All of the JavaMail classes you need are included with the App Engine SDK. Do not add Oracle®'s JavaMail JARs to your app; if you do, the app will throw exceptions."
I have App Engine SDK included in the project, else the hello world program wouldn't have worked. I can't figure out why the import statements are not resolving.
Here is my build.gradle file for reference. Would appreciate your help.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.14'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.14'
compile 'javax.servlet:servlet-api:2.5'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
Okay I managed to solve the issue after a few hours by adding one extra line in the build.gradle file.
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.18'
compile 'javax.servlet:servlet-api:2.5'
}
So it turns out that simply having
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
was not sufficient. I had the impression that it was sufficient because I could run the hello world program just fine (i.e. deploying to the backend using GAE's tools worked, which implies that the sdk dependency was registered). However, when I tried calling specific libraries from within the sdk itself within the Java code, they could not be resolved.
The fix was to add a compilation dependency.
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.18'
I was not able to find the information from the official docs though. In fact, I wouldn't have known how to phrase the compilation dependency properly if not for this article and the maven repo.
Hopefully this helps anyone using the GAE libraries in their code.