I am having a problem that seems to be quite popular on this plattform,
yet no answer seems to work for me. I am facing a similar problem to this:
Error:(23, 17) Failed to resolve: junit:junit:4.12
But none of the 43 answers are applicaple to my problem.
(I hope this won't be marked as duplicate)
I have tried importing the org.junit package to the test class manually, but it couldn't resolve it. I figured that the reason for this is that Gradle can't load the JUnit library, but I have no clue how to change that.
Even upon creating a new android studio project, I have problems setting up JUnit. Not even the example tests can be ran:
package de.ckc.azubis.fleetparkmanagement;
import static junit.framework.Assert.assertEquals;
/**
* Example local unit test, which will execute on the development machine
(host).
*
* #see Testing documentation
*/
public class ExampleUnitTest {
#Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
When I try to import the Test annotation, the JUnit dependency gets added to the gradle file, but does not get imported to the test class.
here my module level build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "de.ckc.azubis.fleetparkmanagement"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:cardview-v7:27.0.2'
}
and my project level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried everything i can think of, including reconfiguring the dependencies, manually adding every repository i could think of (mavenCentral, jcenter...), checked my proxy settings and much more.
There was a problem with caching.
I fixed it by clicking on file -> Invalidate Caches and then restart
I resolved it by selecting Junit4 from Settings -> JunitGenerator -> Properties ->Default Template :
Related
I an trying to import Ksoap2 library in android studio using .jar file version 3.6.4. I have successfully implemented the jar file to android studio. However, on the module app activity when I try to import e.g. import "org.ksoap2.SoapEnvelope;", it gets and error it shows following results:
Execution failed for task ':app:checkDebugAarMetadata'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.google.code.ksoap2-android:ksoap2-android:3.6.4.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/google/code/ksoap2-android/ksoap2-android/3.6.4/ksoap2-android-3.6.4.pom
- https://dl.google.com/dl/android/maven2/com/google/code/ksoap2-android/ksoap2-android/3.6.4/ksoap2-android-3.6.4.pom
- https://jcenter.bintray.com/com/google/code/ksoap2-android/ksoap2-android/3.6.4/ksoap2-android-3.6.4.pom
Required by:
project :app
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Also the imports library have error, please see the pic:
Here is the Build.gradle module code:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is Build.gradle(app) Module code:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.kowloondairycompanykdl.milk_ic"
minSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation files('libs\\ksoap2-android-assembly-3.6.4.jar')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
}
Please help me, I been stuck here for a long time. How to fix the error and how can I implement the Ksoap2 library properly. Thanks
There doesn't seem to be a 3.4.3 version of that library. There's a 3.4.0. And the newest is 3.6.4. You're going to need to use one of those. I'd move to 3.6.4 as 3.4.0 is over 5 years old, and likely lacks security updates.
Remove the dependencyResolutionManagement block from the setting.gradle file to have your project work the old way.
Related issue: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
I am working on a face recognition app using google API. But android studio says symbol not found.
Here is my activity. All four of them don't work.
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
My build.gradle(module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ece.course.myapplication"
minSdkVersion 19
targetSdkVersion 26
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion "28.0.3"
productFlavors{
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:mediarouter-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.android.support:design:28.0.0'
//implementation 'com.android.support:support-annotations:28.0.0'
//compile 'com.android.support:support-v4:24.2.0'
//compile 'com.android.support:design:24.2.0'
//compile 'com.google.android.gms:play-services-vision:9.4.0+'
}
My build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
//classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I am new to android and confused. I cleaned the project and rebuild it several times. Invalidate cache and restart several times.
Yes Because you have to migrate your project into the androidx.
You are using compileSdkVersion 28
Steps to migrate
Add the following properties to gradle.properties
android.useAndroidX=true
android.enableJetifier=true
From the menu bar: Refactor > Migrate to AndroidX…
Here is the reference for whole process.
You need to Migrate your project to androidx
Refactor > Migrate to Androidx
Another thing to remember is to check all your packages are correct in gradle. The Snackbar package for androidx is:
com.google.android.material.snackbar.Snackbar
Answered here:
Snackbar package in AndroidX
For Androidx artifact mapping. Take a look at the Android Developer API here:
https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
Sample:
Artifact Mapping Sample
Thanks everyone for the answers.
As it turns out, during project setup time I used the "basic activity" as a template for fast setup. But I later realized in the "basic activity" in newer version of Android Studio uses AndroidX instead of Android Suppor library. And all my code is based on the legacy android library.
In the file gradle.properties file(located in the base directory of your project same as gradlew), change
android.useAndroidX=true
android.enableJetifier=true
to
android.useAndroidX=false
android.enableJetifier=false
If you have all the dependency right and rebuild and cleared cache several times, still the android support library doesn't work. And if you have a newer version of android studio. It's possible that gradle.properties are wrong.
I am having some issue with my android studio, I recently updated my android studio to version 3.5 and since then I having been encountering with Gradle build error.
I even went ahead and created a new project with no code and an empty activity, when sync it compile without any issue. but upon launching it on my virtual device emulator, it brings this Gradle error
C:\Users.gradle\caches\transforms-2\files-2.1\995db56542b8715d4dfc10fddfcc653d\aapt2-3.5.0-5435860-windows
Config file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App's config:
[apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.loyalteams.application"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: \['*.jar'\])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}][1]
I was able to fix it, it was due to paint virus that was on my pc, so during Gradle runtime and build, the hijack any exe file resulting in Gradle cache build error.
As the sole aim of this malware was to affect any runnable exe file on one's desktop and at the same time reduce the size to some kb.
What I did to fix the issue was to install Malwarebytes and Rkill to fix the issue.
I hope this helps some of us being face with the same issue.
In the main configuration file build.gradle compare what lines you have for example I have these:
What was missing is that of google() in the allprojects;
==========================================================
The gradle-wrapper.properties configuration file should look like this:
Finally I found,
I try change versions and more (taked one day from me)
Do those steps:
Remove .gradle directories
Remove all *.iml files
Remove .idea files
Reopen project
Remove intellij system directory (it is contains caches)
Everyhitg work fine ;)
After the new update of Android Studio (3.3.0) I'm getting error from Gradle sync saying "ERROR: Cause: invalid type code: 68". Even in project, that have been created before the update and hasn't changed at all.
I've tried to reinstall Android Studio, which hasn't helped either, so there has to be something incompatible with my project, but it doesn't say what and why.
App gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "cz.cubeit.cubeit"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
Project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.11'
ext.anko_version='0.10.7'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I had the same problem. I was working on a project on two PCs: one at my office and one at home. In my office, after the AS 3.3 update, everything was fine but at home, after the same steps that I did at the office, the Error code 68 came out.
After a couple of hours, I figured out how to solve it.
Android Studio 3.3 has the " Only sync the active variant" option enabled by default in Settings>Experimental. Disabling this feature resolved the problem. But reactivating the feature the same error shows up, even after a successful Gradle sync. So I think this isn't a complete solution, but at least now I can work.
I had the same issu with IntelliJ 2019.1, Untick this option works for me.
Alter path JDK location to .....\Android Studio\jre
I got a similar message ("invalid type code: E5") and resolved it by first building from the command line, which revealed it was a Firebase libs version conflict, and then switching to use firebase-bom instead of manually specifying each version.
I had the same error (6C) during a LinkedIn Learning course, I managed to solve it through the following steps
Updating Kotlin in project-level build.gradle file
Update gradle build version in project-level build.gradle file.
Open Project Structure and using the Suggestions tab, update all modules to the latest version.
Update the compileSdkVersion & targetSdkVersion to latest.
hi im from iran and we cant use gradle without proxy but now i cant use it with proxy too i dont know why i change every thing but still i cant i have my Cicsco Connection on please help me this is my gradle files
module build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "test.example.test.com.test"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
// google support library ---------------------------------------------------------------------
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support:support-vector-drawable:27.1.1'
}
and project gradle
buildscript {
repositories {
google ()
jcenter{ url "http://jcenter.bintray.com/" }
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google ()
jcenter{ url "http://jcenter.bintray.com/" }
maven { url 'http://repo1.maven.org/maven2' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and this is the errors i got
1:Cause: dl.google.com:443 failed to respond
2:org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'
3: Could not GET 'http://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'
4: Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'.
Gradle has it's own dependency management system similar to maven. I think parts of the gradle publish plugin are backed by maven in some way (not verified). Regardless you shouldn't have to worry about that level of depth, gradle will handle it. Your problem is setting up the proxy. You just need to set some variables in $projectDir/gradle.properties, for example:
#http proxy setup
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
This can be used to download dependencies without proxy. If you want to use a proxy for you can use the code as below instead of above code.
systemProp.https.proxyPort=3128
systemProp.http.proxyHost=192.168.16.2
systemProp.https.proxyHost=192.168.16.2
systemProp.http.proxyPort=3128
Proxy port and host can be changed as you want.
i solve the problem by just edit the gradle properties i added a proxy and i forgot that was my problem