Android Studio: Cannot import libraries JUnit and Truth - java

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.

Related

Firebase dependency isnt showing up?

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'

import android.bluetooth.BluetoothDevice in a module

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.

The import org.mockito.Mock cannot be found

I am experiencing a problem I hope you can help with.
I want to use Mockito in my Spring Boot w/Gradle project, but STS cannot resolve the dependancy.
I have the following in my build.gradle file;
repositories { jcenter() }
dependencies { testCompile('org.mockito:mockito-core:1.+') }
When I do a ./gradlew --info build I can see that it is resolving Mockito:
Resolved versions: {org.mockito:mockito-core=1.+}
Using version '1.+' for dependency 'org.mockito:mockito-core:1.+'
Using version '1.+' for dependency 'org.mockito:mockito-core:1.10.19'
After a ./gradlew cleanEclipse eclipse it is in my STS Project's Build Path
My Code File is showing the following message:
I have another project, setup in exactly the same way and it is working fine.
Please help me out guys, Luke.
Use with a static import:
import static org.mockito.Mockito.when; ...or...
import static org.mockito.Mockito.*;
To add to #Harshad's response, you can make your life easier and let Eclipse handle the static imports by adding the mockito methods to your favorite imports
This will then result in the following hint:
Add the dependencies with androidTestImplementation "org.mockito:mockito-core:2.28.2" instead of the testImplementation "org.mockito:mockito-core:2.28.2"
The dependencies added with androidTestImplementation will be available in:
app\src\androidTest
The dependencies added with testImplementation will only be available in the android test folder available on:
app\src\test
Add testCompile('org.mockito:mockito-core:3.1.0') dependency to build.gradle and then download sources works for me in Netbeans IDE. Version number can be different.

Cannot resolve symbol using App engine's sample code for Java Mail

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.

Gradle: package com.parse does not exist

I am trying to add the Parse SDK into my app. Here is the steps I took:
Dragged all Parse files into my libs folder
Add the following lines to my code:
import com.parse.Parse;
import com.parse.ParseAnalytics;
Went to my build.gradle and added:
compile files('libs/Parse-1.4.1-javadoc/Parse-1.4.1.jar')
However I am still getting these errors:
Gradle: package com.parse does not exist
Gradle: package com.parse does not exist
Change compile files('libs/Parse-1.4.1-javadoc/Parse-1.4.1.jar') to compile files('libs/Parse-1.4.1.jar')
If you see your jar file in explorer on the left side, click right button of your mouse and then 'Add as Library'. It just helped me.
I added the Parse-SDK into my app as follows:
Dependency: Add this in your root build.gradle file (not your module build.gradle file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Then, add the library to your project build.gradle
dependencies {
implementation "com.github.parse-community.Parse-SDK-Android:parse:*latest.version.here*"
// for FCM Push support (optional)
implementation "com.github.parse-community.Parse-SDK-Android:fcm:*latest.version.here*"
// for Kotlin extensions support (optional)
implementation "com.github.parse-community.Parse-SDK-Android:ktx:*latest.version.here*"
}
replacing latest.version.here with the latest released version (in my case 1.18.5).
More details here: https://github.com/parse-community/Parse-SDK-Android/.
I am not to sure if that achieves the same purpose as what you wanted.

Categories

Resources