i have used following dependencies.
it gives me "Default FirebaseApp is not initialized in this process.Make sure to call FirebaseApp.initializeApp(Context) first."
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
/*compile('org.apache.httpcomponents:httpcore:4.4.1') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}*/
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile('com.google.api-client:google-api-client-android:1.22.0')
compile('com.google.apis:google-api-services-script:v1-rev6-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile 'pub.devrel:easypermissions:0.1.5'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'me.spark:submitbutton:1.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
testCompile 'junit:junit:4.12'
compile files('libs/org.apache.http.legacy.jar')
}
This has little to do with your dependencies, you'll need to initialize Firebase before using it in your code.
So at the very beginning (Or at least before you make any references to Firebase) add the following:
FirebaseApp.initializeApp(getContext());
In Your Project gradle file put this dependancy
classpath 'com.google.gms:google-services:3.0.0'
and than your module gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
apply plugin: 'com.google.gms.google-services'
it Work for me.
Put this line at the bottom of your app build.gradle file (* last statement)
apply plugin: 'com.google.gms.google-services'
and also check if you are using this dependency in upper gradle file
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
//classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
You have to initialize Firebase befor you use it and best place to initialize it in Application Class
public class App extends BaseApplication {
public static App _appContext = null;
public static final String TAG = App.class.getSimpleName();
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
_appContext = this;
Firebase.setAndroidContext(getApplicationContext());
FirebaseApp.initializeApp(getContext());
}
}
And add it to mainifiest file Application Tag like
<application
android:name="your.path.to.App"
.
.>
Than try and let me know
You can try this
Remove:
Firebase.setAndroidContext(this);
FirebaseApp.initializeApp(this);
And put:
FirebaseDatabase database = FirebaseDatabase.getInstance();
Related
After a couple of hours I decided to share my problem.
// Root build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.1.0'
classpath "io.realm:realm-gradle-plugin:5.4.1"
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'http://jitpack.io'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// App build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
repositories {
google()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven { url 'https://dl.bintray.com/siclo/SicloAndroidOSS' }
}
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
dexOptions {
javaMaxHeapSize "4g"
jumboMode true
preDexLibraries = false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
multiDexEnabled true
applicationId "my.chart.card.app"
minSdkVersion 17
targetSdkVersion 28
versionCode 63
versionName "2.1.7"
vectorDrawables.useSupportLibrary = true
}
// SOME GRADLE CODE BUT I CUT IT (build release ...)
ext.ANDROID_SUPPORT_LIBRARY_VERSION = "28.0.0"
ext.GOOGLE_PLAY_VERSION = "16.0.0"
ext.FIREBASE_VERSION = "16.0.4"
dependencies {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v13'
all*.exclude group: 'com.google.firebase', module: 'firebase-crash'
all*.exclude group: 'com.google.protobuf', module: 'protobuf-lite'
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:' + ANDROID_SUPPORT_LIBRARY_VERSION
implementation 'com.android.support:support-v4:' + ANDROID_SUPPORT_LIBRARY_VERSION
implementation 'com.android.support:exifinterface:' + ANDROID_SUPPORT_LIBRARY_VERSION
implementation 'com.android.support:percent:' + ANDROID_SUPPORT_LIBRARY_VERSION
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:' + ANDROID_SUPPORT_LIBRARY_VERSION
implementation 'com.android.support:cardview-v7:' + ANDROID_SUPPORT_LIBRARY_VERSION
implementation 'com.google.android.gms:play-services-location:' + GOOGLE_PLAY_VERSION
implementation 'com.google.android.gms:play-services-places:' + GOOGLE_PLAY_VERSION
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.firebase:firebase-core:' + FIREBASE_VERSION
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-database:16.0.3'
implementation 'com.google.firebase:firebase-auth:' + FIREBASE_VERSION
implementation 'com.google.firebase:firebase-storage:16.0.3'
implementation ('com.firebaseui:firebase-ui-firestore:4.2.0') {
exclude group: "com.google.protobuf", module: "protobuf-lite"
}
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'com.simmorsal.library:concealer_nested_scroll_view:2.0.0'
implementation 'jp.wasabeef:recyclerview-animators:2.2.7'
implementation 'com.gmail.samehadar:iosdialog:1.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
implementation 'io.card:android-sdk:5.5.1'
implementation 'com.google.guava:guava:23.6-android'
implementation 'com.cleveroad:slidingtutorial:1.0.8'
implementation 'com.github.takusemba:spotlight:1.1.3'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
implementation 'com.irozon.sneaker:sneaker:1.0.3'
implementation('com.lamudi.phonefield:phone-field:0.1.3#aar') {
transitive = true
}
implementation 'uk.co.deanwild:flowtextview:2.0.2#aar'
implementation 'de.greenrobot:eventbus:2.4.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.facebook.android:facebook-login:4.37.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.algolia:algoliasearch-android:3.+'
implementation 'com.github.takusemba:multisnaprecyclerview:1.3.3'
implementation 'com.github.livefront:bridge:v1.1.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.commonsware.cwac:provider:0.5.0'
implementation 'io.intercom.android:intercom-sdk-base:5.+'
implementation('io.intercom.android:intercom-sdk-fcm:5.+') {
exclude group: 'io.intercom.android', module: 'intercom-sdk-base'
}
implementation 'com.siclo.ezphotopick:library:1.0.8'
}
apply plugin: 'com.google.gms.google-services'
Since I updated to 3.2.1 and google play services to 4.1.0 and added Firebase/Firestore libraries I got this error :
Error: Program type already present: com.google.protobuf.DescriptorProtos$DescriptorProto$Builder
I tried ./gradlew :app:dependencies > ./dependencies.txt and exclude protobuff like this exclude group: "com.google.protobuf", module: "protobuf-lite" but it seems to be wrong, still the error.
gradle-4.6-all.zip
Android studio 3.2
If someone encounters the same problem and have some solution,it would be nice.
The duplicate one was inside this lib
implementation('com.lamudi.phonefield:phone-field:0.1.3#aar')
But I don't know why ./gradlew :app:dependencies didn't show the evidence.
The problem comes from your com.lamudi.phonefield dependency. There is a googlecode dependency that causes the crash.
Try to fork and update to implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.3'
The lib is not maintained anyway. Otherwise, there is this fork existing: https://github.com/ialokim/android-phone-field
Downgrading firestore to v12.0.0 removes this conflict
Where can I find the android support library with ActivityCompat.getReferrer() this function ?
I thought it would be in
my build.gradle looks like this: compile 'com.android.support:support-v4:24.0.1' but its not working.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//Google
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.google.android.gms:play-services-base:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.android.support:support-v4:24.0.1'
compile 'com.android.support:percent:24.0.0'
}
I am trying to access ActivityCompat.getReferrer() from a activity that extends AppCompatActivity in android.support.v7.app package but I can't find this method
Only compile 'com.android.support:appcompat-v7:24.2.1' is enough for that method as it is a method of ActivityCompat. Please use same versions' of libraries from support library.
Java code sanple
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Uri uri = ActivityCompat.getReferrer(SplashActivity.this);
if (uri != null)
Toast.makeText(SplashActivity.this,uri.toString(),Toast.LENGTH_SHORT).show();
}
}
A week ago I started implement Chat System to my app using Smack API (4.1.8 version). And It works well on Lolipop device and Marshmallow too. But on Kitkat( API 19) I get exception NoClassDefFoundError
LogCat:
Process: mobi, PID: 23510
java.lang.NoClassDefFoundError: org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration
at mobi.networking.ChatXMPPConnection.connect(ChatXMPPConnection.java:76)
at mobi.networking.ChatXMPPService.initConnection(ChatXMPPService.java:80)
at mobi.networking.ChatXMPPService.access$100(ChatXMPPService.java:36)
at mobi.networking.ChatXMPPService$1.run(ChatXMPPService.java:112)
at java.lang.Thread.run(Thread.java:841)
So what is it on the line 76(the first line):
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(mUsername, mPassword);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setResource("Android");
configBuilder.setServiceName(DOMAIN);
configBuilder.setHost(HOST);
configBuilder.setPort(PORT);
My build-gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
dataBinding
{
enabled = true
}
defaultConfig {
applicationId "mobi"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.1'
compile 'com.android.support:design:24.0.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.android.support:recyclerview-v7:24.0.1'
compile 'com.zaihuishou:expandablerecycleradapter-databinding:1.0.0'
compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-SNAPSHOT'
compile 'com.kyleduo.switchbutton:library:1.4.1'
compile 'info.hoang8f:android-segmented:1.0.6'
compile 'com.github.Kennyc1012:BottomSheet:2.3.1'
compile 'com.aurelhubert:ahbottomnavigation:1.3.3'
compile 'com.vk:androidsdk:1.6.5'
compile 'com.brucetoo.pickview:library:1.2.2'
compile 'gun0912.ted:tedpermission:1.0.0'
compile 'com.squareup.okio:okio:1.11.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.basgeekball:awesome-validation:1.3'
compile 'com.google.code.gson:gson:2.4'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.github.aakira:expandable-layout:1.6.0#aar'
compile 'fr.xebia.android.freezer:freezer:2.0.3'
provided 'fr.xebia.android.freezer:freezer-annotations:2.0.3'
apt 'fr.xebia.android.freezer:freezer-compiler:2.0.3'
compile "me.henrytao:smooth-app-bar-layout:24.2.1.0"
compile ("org.igniterealtime.smack:smack-android-extensions:4.1.8") {
exclude group: 'xpp3', module: 'xpp3'
}
compile ("org.igniterealtime.smack:smack-tcp:4.1.8"){
exclude group: 'xpp3', module: 'xpp3'
}
compile ("org.igniterealtime.smack:smack-experimental:4.1.8"){
exclude group: 'xpp3', module: 'xpp3'
}
}
}
also, my libs folder is empty. I don't use jar-files
Link to Smack-Wiki https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-and-Upgrade-Guide#using-eclipses-android-development-tools-adt-ant-based-build
Please, help, I loose two days on fixing it
I was also facing the same issue.
Try adding the following dependency:
compile 'com.android.support:multidex:1.0.1'
and in your application class add this,
#Override
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(BaseApplication.this);
}
public class StringUtilsTests extends TestCase {
String message;
#Override
protected void setUp() throws Exception {
super.setUp();
message = "33,333";
}
/**
*
*/
public void testCommaToSpaces() {
String result = StringUtils.commasToSpaces(message);
assertEquals("33 333", result);
}
}
build.gradle :-
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'
// Unit testing dependencies
testCompile 'junit:junit:4.12'
// Set this dependency if you want to use Mockito
testCompile 'org.mockito:mockito-core:1.10.19'
}
testOptions {
unitTests.all {
// All the usual Gradle options.
jvmArgs '-XX:MaxPermSize=256m'
}
}
sourceSets {
unitTest {
java.srcDir file('src/androidTest/java')
}
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/results-tests")
}
task unitTest(type: Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
check.dependsOn unitTest
I tried lot of things after googling more than a day, but test reports - xml/html are not getting generated. Please kindly guide if anyone has any idea on this.
If i add below line then gradle sync failed.
reports.html.enabled = true
Did you add the line below in your gradle script?
buildTypes {
debug {testCoverageEnabled = TEST_COVERAGE}}
There is an export results option in the test runner. Once the tests have been executed, you can export these results as .html or .xml
It's the right most option.
Click here to see where it is
When executing ./gradlew clean connectedAndroidTest with the following configuration... I'm getting No tests found
This is my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.1'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.0.1'
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
jcenter()
}
}
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LGP2.1'
exclude 'META-INF/LGPL2.1'
}
compileSdkVersion 21
buildToolsVersion "21.1.0"
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "com.example"
minSdkVersion 9
targetSdkVersion 21
versionCode 2
versionName "0.1"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
}
}
sourceSets {
androidTest {
setRoot('src/espressoTest')
}
}
}
apply plugin: 'android-unit-test'
dependencies {
// App
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:gridlayout-v7:18.0.0'
compile 'joda-time:joda-time:2.3'
compile 'com.google.code.gson:gson:2.2.4'
compile 'de.greenrobot:eventbus:2.0.2'
compile 'com.squareup.dagger:dagger:1.1.0'
compile 'com.squareup.dagger:dagger-compiler:1.1.0'
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.picasso:picasso:2.3.4'
compile 'com.squareup:otto:1.3.5'
compile 'com.google.guava:guava:18.0'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.wrapp.floatlabelededittext:library:0.0.3'
compile 'com.daimajia.swipelayout:library:1.0.7#aar'
compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
compile 'info.hoang8f:android-segmented:1.0.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.androidanimations:library:1.1.2#aar'
compile 'com.balysv.materialmenu:material-menu-toolbar:1.4.0'
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
// Robolectric
testCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
testCompile files('lib/robolectric-2.4-SNAPSHOT-jar-with-dependencies.jar')
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'com.squareup:fest-android:1.0.+'
testCompile 'com.googlecode.catch-exception:catch-exception:1.2.0'
}
tasks.findByName("assembleDebug").dependsOn("testDebugClasses")
This is the class for the tests under src/espressoTest:
package com.example;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import com.betavalue.myvalue.MainActivity;
import com.betavalue.myvalue.R;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
#LargeTest
public class MainEspressoTest extends ActivityInstrumentationTestCase2<MainActivity> {
#SuppressWarnings("deprecation")
public MainEspressoTest() {
// This constructor was deprecated - but we want to support lower API levels.
super(MainActivity.class);
}
#Override
public void setUp() throws Exception {
super.setUp();
// Espresso will not launch our activity for us, we must launch it via getActivity().
getActivity();
}
public void testCheckText() {
onView(withId(R.id.text))
.check(matches(withText("Hello Espresso!")));
}
}
And MainActivityis an empty Activity just to try testing.
Any ideas? Is there something on the AndroidManifest.xml I could be missing?
If anyone is having this issue... It just solved automatically when pulling it from my repository again.
It had to do something with Android Studio cache.