Roboelectric 3.0 testing fragments - android

I am new to Roboelectric testing.
I am trying to follow this post to test fragments. I am using following as dependency
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile "org.robolectric:robolectric:3.0"
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v4:22.1.0'
compile 'com.google.android.gms:play-services:7.5.0'
}
But this import is giving me compilation issues, and I am not able to resolve the symbol SupportFragmentTestUtil to start with. Kindly guide me what I am missing??
org.robolectric.shadows.support.v4.SupportFragmentTestUtil

You need to add the dependency for v4 shadows support. Add this in your dependency file.
testCompile "org.robolectric:shadows-support-v4:3.0"

Related

Android Studio Rendering Problems: android.support.design.widget.TabLayout class not found

When I add TabLayout inside my xml file it shows this error.
I also have these dependencies.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
}
See Code here
Add this dependency in gradle
compile 'com.android.support:design:23.1.0'
You can try to build it or change preview Android version in here Preview Android Version

InstaBug, cannot resolve 'Builder'

Trying to implement InstaBug first time, however, when I initialize it,
new Instabug.Builder(this, "XXXXXXXXXXXXXXXXXXXX")
.setInvocationEvent(Instabug.IBGInvocationEvent.IBGInvocationEventShake)
.build();
Android Studio says cannot resolve symbol Builder
Though Builder extends from java.lang.Object , helpless to figure why this happens. Any fix?
EDIT:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.code.gson:gson:2.5'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile "com.google.android.gms:play-services:8.4.0"
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:design:+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.commit451:PhotoView:1.2.4'
compile 'net.danlew:android.joda:2.9.1'
compile project(":volley")
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile ("com.instabug.library:instabugsupport:+") { exclude group: 'com.mcxiaoke.volley', module: 'library' }
Instabug.Builder was introduced in v2+ of Instabug SDK.
Can you try specifying the latest version of Instabug in your gradle, as follows:
compile('com.instabug.library:instabugcompat:2.2.1')
P.S: v2.2.1 was latest at the time of writing
P.S2: instabugcompat is the equivalent of instabugsupport in v2+
P.S3: Instabug doesn't include Volley anymore so you don't need to exclude it anymore
For more details, don't hesitate to ask. And you can check this out as well as #m-d mentioned

XML resource conflict in Android library

I have imported two libraries in my Android Studio project through gradle. One is support library v7 which is a necessary component to handle action bar in my app for different platforms. Another is the one I intent to use for UI components called MaterialDesign.
Problem is that both libraries have defined an attribute in their values.xml called rippleColor and gradle identifies the conflict.
How can I tell gradle to exclude one definition and accept the other?
Manifest Merging in android developers hub seem to do that over the entire xml file whereas my problem is only one specific attribute in that file.
Is there any way that I can get around this problem?
P.S. my gradle dependencies are as follows:
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'org.xwalk:xwalk_core_library:15.44.384.13'
compile 'com.github.navasmdc:MaterialDesign:1.5#aar'
Write below code in your grade file. It might help:
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile fileTree(dir: 'libs', include: '*.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
}

Android Studio cannot resolve symbol 'TabLayout'

Cannot resolve symbol TabLayout ? How to clear this error? Please help me. I already imported import android.support.design.widget.TabLayout;
Had a similar problem, to fix this in Android Studio (AS) I went Build->Clean Project and AS sorted everything out. Make sure in your build.gradle file under dependencies that you have:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:your_api_version_number.0.0'
compile 'com.android.support:design:+'
}
I solved the issue Manually by adding the following two lines:
implementation 'com.android.support:support-v4:22.2.0'
implementation 'com.android.support:design:22.2.0'
under dependencies in \app\build.gradle worked for me.
Note: Your all the support libraries have to be the same version i.e. appcompat-v7 and support-v4 to same version e.g. 23.0.1; otherwise you can get this error
java.lang.NoClassDefFoundError: android.support.v7.internal.widget.TintManager`
after code build
Under Gradle Scripts,
Open build.gradle (Module: app)
Inside of dependencies add
compile 'com.android.support:design:25.3.1'
There may be a newer version of the library available, the android studio lint check may detect that.
The full dependencies area may look like this for reference. The above line is the only one I manually added.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
}
An above answer suggested adding
compile 'com.android.support:design:+'
Which is kind of dangerous because it always uses the latest library, you may have trouble isolating bugs with automatic library updates happening in the background.
Android Studio no longer uses "compile", they use "implementation".
Be sure to include the code below when you go to Build Gradle>dependencies{
implementation fileTree(dir: 'libs', include: ['*.jar'])
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'
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'
}
For Android API Level 29+, add the following dependency in build.gradle (Module:app):
dependencies {
implementation 'com.google.android.material:material:1.0.0'
}
If there is a newer version available, Android Studio will prompt you to use the newest one.
I solve it by Open build.gradle (Module: app) and add
implementation 'com.android.support:design:+'

Facebook SDK v4.0.1 Failing to compile with gradle

I am having trouble using Gradle to build Facebook SDK 4.0.1 in Android Studio 1.2 beta. There is no compile error, but the compiled library is not in my External Libraries. Previously, I successfully had:
compile 'com.facebook.android:facebook-android-sdk:3.22.0'
However,
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
doesn't appear to do anything. From searching, it looks like this version is available on maven. Here is my complete dependency list:
dependencies {
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.parse.bolts:bolts-android:1.2.0'
compile 'com.mixpanel.android:mixpanel-android:4.5.3#aar'
compile 'net.hockeyapp.android:HockeySDK:3.5.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.87'
//compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':libraries:downloader_library')
compile project(':libraries:zip_file')
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
testCompile 'junit:junit:4.12'
}
I also have had some difficulties with Google Play Services 7.0.0, hence the comment.
Is there something I am doing wrong, such as a missing dependency or an incorrect assumption?
Solved
It turns out you can't have comments in your dependencies, so removing
//compile 'com.google.android.gms:play-services:7.0.0'
Fixed the issue.

Categories

Resources