I have successfully migrated to Androidx, everything seems to work. Now I'm stuck in migrating (or basically creating tests) for my project.
I added those dependencies to my project:
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.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'ch.acra:acra:4.6.1'
implementation 'com.squareup.okhttp3:okhttp:4.2.1'
implementation 'com.diegocarloslima:fgelv:0.1.2'
implementation 'com.luckycatlabs:SunriseSunsetCalculator:1.1'
implementation project(':cp963_cpik_lib')
I created two paths for two tests (one is for test which works fine and Android studio recognize the #Test annotation of junit class, the other is for androidTest which Android studio does not recognize any of the classes). Both test and androidTest are green and have the same package name as my src folder.
This is the test file (works just fine):
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* #see Testing documentation
*/
public class ExampleUnitTest {
#Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
This is androidTest that I'm not sure why Android Studio is not able to import any of the classes
#RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
#Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("xxxxxx", appContext.getPackageName());
}
}
The classes that I mean are #RunWith, AndroidJUnit4, #Test, InstrumentationRegistry, assertEquals.
I basically used the generated tests that came with a new project. Do I need somehow to configure Android Studio to use junit in androidTest? or is it something to do with the copilot library that I'm using?
Thank you
Edit 1
I added the previous test that was in my project:
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
It's an old project which I'm trying to use more up to date dependencies and unit testing.
Edit 2
This is my build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 19 // 17 = 4.2 Jelly Bean, 18 = 4.3 jelly bean, 19 = 4.4 kitkat
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 19 // 21 = 5.1 Lollipop
versionCode 65
versionName "1.65"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
signingConfig signingConfigs.config
}
}
}
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.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-identity:17.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'ch.acra:acra:4.6.1'
implementation 'com.squareup.okhttp3:okhttp:4.2.1'
implementation 'com.diegocarloslima:fgelv:0.1.2'
implementation 'com.luckycatlabs:SunriseSunsetCalculator:1.1'
implementation project(':cp963_cpik_lib')
androidTestImplementation 'junit:junit:4.12' // I tried with this and without but I got the same result.
}
Related
I keep getting the Cannot resolve class android.support.v4.widget.DrawerLayout error even after adding both the DrawerLayout androidx.drawerlayout:drawerlayout:1.1.1 and Material com.google.android.material:material:1.0.0 implementations in my build.gradle file.
I have tried adding other implementations, such as com.android.support:support-compat:28.0.0 and com.android.support:design:25.0.0, but the error remains and the app won't start.
Any idea on how to fix this?
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "edu.ktu.birthdaycalendar"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
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'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
def room_version = "2.2.5"
def lifecycle_version = "2.2.0"
def arch_version = "2.1.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"
//lifecycle
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
androidTestImplementation "androidx.arch.core:core-testing:$arch_version"
implementation "com.google.android.material:material:1.0.0"
/*implementation "com.android.support:support-compat:28.0.0"
implementation "com.android.support:design:25.0.0"
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:support-v4:27.1.1"
implementation "com.android.support:design:27.1.1"
//implementation 'com.android.support.constraint:constraint-layout:1.1.0' */
}
You've imported the wrong version of DrawerLayout. android.support.v4.widget.DrawerLayout
It should be import androidx.drawerlayout.widget.DrawerLayout
Check the class mapping between the support libraries and androidx libraries:
android.support.v4.widget.DrawerLayout -> androidx.drawerlayout.widget.DrawerLayout
Use in your layout and in your code androidx.drawerlayout.widget.DrawerLayout.
Am working with an MVVM design pattern ,implementing Observers and things. but all of the sudden Observer Class not found.
error: cannot find symbol class Observer
I have tried
Rebuilding project
clean project
Invalidate/caches & restart
But still no Improvement
here is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
dataBinding{
enabled=true
}
defaultConfig {
applicationId "com.istrides.petool"
minSdkVersion 17
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.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.12'
compile project(':horizontalcalendar')
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.synnapps:carouselview:0.1.5'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation 'com.facebook.shimmer:shimmer:0.1.0#aar'
//mvvm
def lifecycle_version = "2.1.0"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
}
Please try adding these libraries in build.gradle
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'
After implement Firebase on my two projects, AppCompatActivity along with import androidx.appcompat.app.AppCompatActivity and import android.support.v7.app.AppCompatActivity are not found.
I've been looking for five hours. And even after removing the implementation it doesn't work.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.company.pc.livium"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
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:cardview-v7:28.0.0'
implementation 'com.anjlab.android.iab.v3:library:1.0.44'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
Go to Refactor -> Migrate to AndroidX… and migrate your project to AndroidX.
AppCompat is deprecated, your build.gradle should look something like this under depenedencies {}:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
You can try:
1. Build -> Clean project than Build -> Rebuild Project
if that doe not help
2. File -> Invalidate Caches/Restart (Take a few minutes to perform)
compile project failed with error "cannot find symbol class GlideApp" after added room components to the gradle config file. Project compile without error if comment out "annotation processor "android.arch.persistence.room:compiler:$room_version". Any ideas?
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.otpuskarche.onleave"
minSdkVersion 24
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 {
def room_version = "1.1.1"
def archLifecycleVersion = '1.1.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.code.gson:gson:2.8.3'
implementation 'com.android.support:support-v4:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.android.support:gridlayout-v7:27.1.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
// Room components
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
androidTestImplementation "android.arch.persistence.room:testing:$room_version"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:$archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$archLifecycleVersion"
testImplementation 'junit:junit:4.12'
}
The problem was with room. The schema export directory was not set. Build log feint me as the error appeared on the bottom of the log.
reference to real issue - room-schema-export
Create a call like
#GlideModule
public final class GlideLoader extends AppGlideModule{
}
And Build Project.Then You will access glide by GlideApp.
You need to add the annotationProcessor dependency:
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
You also need to add an AppGlideModule. See the generated API documentation for details.
I am having issues with gradle in my android application.
android {
compileSdkVersion 27
defaultConfig {
applicationId "za.co.gtsolutions.vivachoc"
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "1.5"
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.constraint:constraint-layout:1.1.0'
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.github.bumptech.glide:glide:4.6.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.stripe:stripe-android:6.1.2'
implementation 'com.google.code.gson:gson:2.8.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
implementation 'testfairy:testfairy-android-sdk:1.+#aar'
testImplementation "org.robolectric:robolectric:3.8"
implementation 'com.facebook.android:facebook-login:4.32.0'
android {
testOptions {
unitTests {
includeAndroidResources = true
}
}
}
compile 'com.android.support:cardview-v7:27.1.1'
compile 'com.android.support.test.espresso:espresso-contrib:3.0.1'
}
I get the following error: all com.android.support libraries should use the same version and my application will not run because of this. I have changed the minimumSDK Version and targetVersion to apply to the project that i am working on.
I am totaly lost on what the issue could be ?
use 27.0.2 instead of 27.1.1 like below
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
The answer after sometime is guided by the following answer: All com.android.support libraries must use the exact same version specification was the following:
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation "com.android.support:customtabs:27.1.1"
The application needs to use the customtabs library which was missing