java.lang.NoSuchFieldError: android.support.v4.app.Watson.mFragments - java

I'm trying to implement ActionBarSherlock swipe menu as I like how this animation slides over the slide menu. Unfortunately I keep getting this error and haven't been able to solve it.
This guy is getting the same error but none of the answers on this solves my problem. Android: java.land.NoSuchFieldError after update to SDK 23
Here is my Gradle file.
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: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myegotest.ego_17012016"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
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 'com.squareup.picasso:picasso:2.5.2'
compile 'com.facebook.android:facebook-android-sdk:4.9.0'
compile('com.twitter.sdk.android:twitter:1.12.0#aar') {
transitive = true;
}
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
//compile 'com.android.support:multidex:1.0.1'
compile "com.android.support:support-v4:23.1.1"
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile project(':SlidingMenuLib-master')
}
Here is the activity trying to implement the SlidingMenu.
import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Toast;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.myegotest.ego_17012016.ProfileFragments.InterestsPageFragment;
import com.myegotest.ego_17012016.ProfileFragments.ProfilePageFragment;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.MalformedInputException;
import Library.LocalDataBase;
import Library.User;
public class MainActivity extends SlidingFragmentActivity {
//View item variables
ViewPager mPager;
//Other variables
private String firstName;
private String lastName;
private String username;
String profilepic;
LocalDataBase mLocalDataBase;
//The pager adapter, which provides the pages to the view pager widget.
private PagerAdapter mPagerAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Get logged in user from LocalDataBase and
//Destroy Activity if user is logged out
mLocalDataBase = new LocalDataBase(this);
User user = mLocalDataBase.getLoggedInUserInfo();
if(!mLocalDataBase.userIsLoggedIn()){
MainActivity.this.finish();
}
setBehindContentView(R.layout.menu_frame);
//Get loggedIn user values from the LocalDataBase .
firstName = user.mFirstName;
lastName = user.mLastName;
username = user.mUsername;
//Capitalize 1st letter of the following variable.
firstName = capitalizeFirstCharacter(firstName);
lastName = capitalizeFirstCharacter(lastName);
// Instantiate a ViewPager and a PagerAdapter.
mPager = (ViewPager) findViewById(R.id.myViewPager);
mPager.setPageTransformer(true, new ZoomOutPageTransformer());
netAsync();
}
//Method to capitalize 1st letter of the String thats using this method.
private String capitalizeFirstCharacter(String textInput){
String input = textInput.toLowerCase();
String output = input.substring(0, 1).toUpperCase() + input.substring(1);
return output;
}
/**
* A simple pager adapter that represents 2 ScreenSlidePageFragment objects, in
* sequence.
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch(position){
case 1:
return new InterestsPageFragment();
default: break;
}
return ProfilePageFragment.newInstance(firstName, lastName, profilepic);
}
#Override
public int getCount() {
return 2;
}
}
//Animation for swiping between page views
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
private static final float MIN_SCALE = 0.85f;
private static final float MIN_ALPHA = 0.5f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
view.setAlpha(0);
} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to shrink the page as well
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);
}
// Scale the page down (between MIN_SCALE and 1)
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
// Fade the page relative to its size.
view.setAlpha(MIN_ALPHA +
(scaleFactor - MIN_SCALE) /
(1 - MIN_SCALE) * (1 - MIN_ALPHA));
} else { // (1,+Infinity]
// This page is way off-screen to the right.
view.setAlpha(0);
}
}
}
}
Finally, here is the error I am getting.
E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.myegotest.ego_17012016, PID: 8545
E/AndroidRuntime: java.lang.NoSuchFieldError: android.support.v4.app.Watson.mFragments
E/AndroidRuntime: at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:50)
E/AndroidRuntime: at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:560)
E/AndroidRuntime: at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:64)
E/AndroidRuntime: at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:164)
E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:486)
E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:855)
E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:271)
E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:603)
E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:572)
E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:157)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5293)
E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
I/Process: Sending signal. PID: 8545 SIG: 9

I was able to solve the problem by removing the facebook sdk from my gradle file. Since i need the facebook sdk, i was able to get around this by making MainActivity just extend FragmentActivity instead of SlidingFragmentActivty. I made this inner class inside of MainActivty to extend SlidingActivity, that way i can still use the methods i need.
private class SlidingMenuClass extends SlidingActivity {
private SlidingMenu sm;
public SlidingMenuClass(Context ctx){
sm = new SlidingMenu(ctx);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setBehindContentView(R.layout.menu_frame);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
sm = getSlidingMenu();
sm.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
sm.setShadowWidthRes(R.dimen.shadow_width);
//sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(1f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
sm.setBehindOffsetRes(R.dimen.behindoffsetRes);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
}
return super.onOptionsItemSelected(item);
}
}

Related

Can't import “import com.google.firebase.firestore.MetadataChanges” original question still has no answers

I almost have the same problem as this question but it has no answers.
Can't import "import com.google.firebase.firestore.MetadataChanges"
I am following the codes here at https://openclassrooms.com/en/courses/5086986-create-a-scalable-and-powerful-backend-for-android-using-firebase-in-java/5769306-implement-a-chat-room
Error log
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/firestore/MetadataChanges;
at com.firebase.ui.firestore.FirestoreRecyclerOptions$Builder.setQuery(FirestoreRecyclerOptions.java:86)
at com.sp.firestorechat.mentor_chat.MentorChatActivity.generateOptionsForAdapter(MentorChatActivity.java:126) //blue highlighted
at com.sp.firestorechat.mentor_chat.MentorChatActivity.configureRecyclerView(MentorChatActivity.java:112)//blue highlighted
at com.sp.firestorechat.mentor_chat.MentorChatActivity.onCreate(MentorChatActivity.java:57)//blue highlighted
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.firestore.MetadataChanges" on path: DexPathList[[zip file "/data/app/com.sp.firestorechat-2/base.apk"],nativeLibraryDirectories=[/data/app/com.sp.firestorechat-2/lib/x86_64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.firebase.ui.firestore.FirestoreRecyclerOptions$Builder.setQuery(FirestoreRecyclerOptions.java:86) 
at com.sp.firestorechat.mentor_chat.MentorChatActivity.generateOptionsForAdapter(MentorChatActivity.java:126) 
at com.sp.firestorechat.mentor_chat.MentorChatActivity.configureRecyclerView(MentorChatActivity.java:112) 
at com.sp.firestorechat.mentor_chat.MentorChatActivity.onCreate(MentorChatActivity.java:57) 
at android.app.Activity.performCreate(Activity.java:6679) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
build.gradle file
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.sp.firestorechat"
minSdkVersion 21
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 fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'org.jetbrains:annotations:15.0'
implementation 'com.google.firebase:firebase-auth:20.0.2'
implementation 'com.firebaseui:firebase-ui-auth:3.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "com.google.firebase:firebase-core:18.0.2"
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'
implementation 'com.google.firebase:firebase-firestore:22.0.2'
testImplementation 'junit:junit:4.13.1'
implementation 'com.google.firebase:firebase-database:19.6.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.legacy:legacy-support-v4:"
implementation "androidx.recyclerview:recyclerview:"
implementation 'com.google.firebase:firebase-messaging:21.0.1'
//GLIDE
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
//BUTTERKNIFE
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:7.1.1'
}
apply plugin: 'com.google.gms.google-services'
chat activity
package com.sp.firestorechat.mentor_chat;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.textfield.TextInputEditText;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.Query;
import com.sp.firestorechat.Message;
import com.sp.firestorechat.MessageHelper;
import com.sp.firestorechat.R;
import com.sp.firestorechat.User;
import com.sp.firestorechat.UserHelper;
import com.sp.firestorechat.base.BaseActivity;
import butterknife.BindView;
import butterknife.OnClick;
public class MentorChatActivity extends BaseActivity implements MentorChatAdapter.Listener {
// FOR DESIGN
// 1 - Getting all views needed
#BindView(R.id.activity_mentor_chat_recycler_view) RecyclerView recyclerView;
#BindView(R.id.activity_mentor_chat_text_view_recycler_view_empty)
TextView textViewRecyclerViewEmpty;
#BindView(R.id.activity_mentor_chat_message_edit_text)
TextInputEditText editTextMessage;
#BindView(R.id.activity_mentor_chat_image_chosen_preview)
ImageView imageViewPreview;
// FOR DATA
// 2 - Declaring Adapter and data
private MentorChatAdapter mentorChatAdapter;
#Nullable
private User modelCurrentUser;
private String currentChatName;
// STATIC DATA FOR CHAT (3)
private static final String CHAT_NAME_ANDROID = "android";
private static final String CHAT_NAME_BUG = "bug";
private static final String CHAT_NAME_FIREBASE = "firebase";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.configureRecyclerView(CHAT_NAME_ANDROID);
this.configureToolbar();
this.getCurrentUserFromFirestore();
}
#Override
public int getFragmentLayout() { return R.layout.activity_mentor_chat; }
// --------------------
// ACTIONS
// --------------------
#OnClick(R.id.activity_mentor_chat_send_button)
public void onClickSendMessage() { }
#OnClick({ R.id.activity_mentor_chat_android_chat_button, R.id.activity_mentor_chat_firebase_chat_button, R.id.activity_mentor_chat_bug_chat_button})
public void onClickChatButtons(ImageButton imageButton) {
// 8 - Re-Configure the RecyclerView depending chosen chat
switch (Integer.valueOf(imageButton.getTag().toString())){
case 10:
this.configureRecyclerView(CHAT_NAME_ANDROID);
break;
case 20:
this.configureRecyclerView(CHAT_NAME_FIREBASE);
break;
case 30:
this.configureRecyclerView(CHAT_NAME_BUG);
break;
}
}
#OnClick(R.id.activity_mentor_chat_add_file_button)
public void onClickAddFile() { }
// --------------------
// REST REQUESTS
// --------------------
// 4 - Get Current User from Firestore
private void getCurrentUserFromFirestore(){
UserHelper.getUser(getCurrentUser().getUid()).addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
#Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
modelCurrentUser = documentSnapshot.toObject(User.class);
}
});
}
// --------------------
// UI
// --------------------
// 5 - Configure RecyclerView with a Query
private void configureRecyclerView(String chatName){
//Track current chat name
this.currentChatName = chatName;
//Configure Adapter & RecyclerView
this.mentorChatAdapter = new MentorChatAdapter(generateOptionsForAdapter(MessageHelper.getAllMessageForChat(this.currentChatName)), Glide.with(this), this, this.getCurrentUser().getUid());
mentorChatAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
#Override
public void onItemRangeInserted(int positionStart, int itemCount) {
recyclerView.smoothScrollToPosition(mentorChatAdapter.getItemCount()); // Scroll to bottom on new messages
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(this.mentorChatAdapter);
}
// 6 - Create options for RecyclerView from a Query
private FirestoreRecyclerOptions<Message> generateOptionsForAdapter(Query query){
return new FirestoreRecyclerOptions.Builder<Message>()
.setQuery(query, Message.class)
.setLifecycleOwner(this)
.build();
}
// --------------------
// CALLBACK
// --------------------
#Override
public void onDataChanged() {
// 7 - Show TextView in case RecyclerView is empty
textViewRecyclerViewEmpty.setVisibility(this.mentorChatAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
}
}
these 3 lines of code is the error
.setQuery(query, Message.class)
this.mentorChatAdapter = new MentorChatAdapter(generateOptionsForAdapter(MessageHelper.getAllMessageForChat(this.currentChatName)), Glide.with(this), this, this.getCurrentUser().getUid());
this.configureRecyclerView(CHAT_NAME_ANDROID);

Why I am getting such a message:java.lang.NoSuchMethodError: No virtual method fetchProvidersForEmail(Ljava/lang/String;)

I am trying to create an Android program, and met an error of which I have no idea how to solve.
My app crashes after I put in the email. I suspect that the problem is related with firebase. I have tried different ways of solving of this problem, such as changing the versions of firebase implementations, but without any success.
Here is my code
MainActivity.java
package com.chat.mychatapp;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.database.FirebaseListAdapter;
import com.github.library.bubbleview.BubbleTextView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;
import android.text.format.DateFormat;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
public static int SIGN_IN_CODE = 1;
private RelativeLayout activity_main;
private FirebaseListAdapter<Message> adapter;
private FloatingActionButton sendBtn;
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == SIGN_IN_CODE){
if(resultCode == RESULT_OK){
Snackbar.make(activity_main, "You are authorized", Snackbar.LENGTH_LONG).show();
displayAllMessages();
}else{
Snackbar.make(activity_main, "You are NOT authorized", Snackbar.LENGTH_LONG).show();
finish();
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
activity_main = findViewById(R.id.activity_main);
sendBtn = findViewById(R.id.sendBtn);
sendBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText textField = findViewById(R.id.messageField);
if(textField.getText().toString().equals(""))
return;
FirebaseDatabase.getInstance().getReference().push().setValue(
new Message(Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getEmail(),
textField.getText().toString()
)
);
textField.setText("");
}
});
//User not autorized
if(FirebaseAuth.getInstance().getCurrentUser() == null){
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_CODE);
}else{
Snackbar.make(activity_main, "You are authorized", Snackbar.LENGTH_LONG).show();
displayAllMessages();
}
}
private void displayAllMessages() {
ListView listOfMessages = findViewById(R.id.messageList);
adapter = new FirebaseListAdapter<Message>(this, Message.class, R.layout.list_item, FirebaseDatabase.getInstance().getReference()) {
#Override
protected void populateView(View v, Message model, int position) {
TextView m_user, m_time;
BubbleTextView m_text;
m_user = v.findViewById(R.id.messageUser);
m_time = v.findViewById(R.id.messageTime);
m_text = v.findViewById(R.id.messageText);
m_user.setText(model.getUserName());
m_text.setText(model.getMessage());
m_time.setText(DateFormat.format("dd-mm-yyyy HH:mm:ss",model.getTime()));
}
};
listOfMessages.setAdapter(adapter);
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.chat.mychatapp"
minSdkVersion 19
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.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.firebaseui:firebase-ui:0.6.2'
implementation 'com.github.lguipeng:BubbleView:1.0.1'
//implementation 'com.google.firebase:firebase-firestore:21.3.1'
}
apply plugin: 'com.google.gms.google-services'
Error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chat.mychatapp, PID: 18455
java.lang.NoSuchMethodError: No virtual method fetchProvidersForEmail(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/auth/FirebaseAuth; or its super classes (declaration of 'com.google.firebase.auth.FirebaseAuth' appears in /data/app/com.chat.mychatapp-s_3u6mmiv0A6KE9ijznfqQ==/base.apk)
at com.firebase.ui.auth.ui.AcquireEmailHelper.checkAccountExists(AcquireEmailHelper.java:55)
at com.firebase.ui.auth.ui.email.SignInNoPasswordActivity.onClick(SignInNoPasswordActivity.java:73)
at android.view.View.performClick(View.java:7339)
at android.widget.TextView.performClick(TextView.java:14222)
at android.view.View.performClickInternal(View.java:7305)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27787)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7078)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Update the following dependency:
implementation 'com.firebaseui:firebase-ui:0.6.2'
into this:
implementation 'com.firebaseui:firebase-ui:6.2.0'
https://github.com/firebase/FirebaseUI-Android
From the docs:
Removed the deprecated fetchProvidersForEmail(String) method from the FirebaseAuth class, as well as the associated ProviderQueryResult class. Use fetchSignInMethodsForEmail(String) instead.
Therefore update the firebaseUI and you can use fetchSignInMethodsForEmail(String) instead.

NoSuchMethodError: No virtual method zzEq()Z in class Lcom/google/firebase/FirebaseApp;

Below is the fatal error that I keep getting on my App. I am trying to run a chat messenger feature on my application using Firebase. It was running however it has since kept crashing the app entirely. I've made a few edits to the code in the hope of resolving the issues, but to no avail.
I've been following this tutorial on youtbe https://www.youtube.com/watch?v=Xn0tQHpMDnM and it appears by reading the comments that no one else has a similiar error to me.
According to the log, the errors are found on line 99 - displayChatMessage(); as well as on Line 109 - adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.chat_list_item,FirebaseDatabase.getInstance().getReference()) {
I'm hoping this maybe just a simple code error which I have created, or is it possible it could be to do with my gradle build. Below is the error log I am getting.
FATAL EXCEPTION: main
Process: com.example.aids.a09application, PID: 30713
java.lang.NoSuchMethodError: No virtual method zzEq()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.example.aids.a09application-2/split_lib_dependencies_apk.apk:classes33.dex)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.example.aids.a09application.MainChatActivity.displayChatMessage(MainChatActivity.java:109)
at com.example.aids.a09application.MainChatActivity.onCreate(MainChatActivity.java:99)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Below is the MainActivity Class for the chat messenger in my application:
package com.example.aids.a09application;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.text.format.DateFormat;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.database.FirebaseListAdapter;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;
/**
* Created by Aids on 29/08/2017.
*/
public class MainChatActivity extends AppCompatActivity {
private static int SIGN_IN_REQUEST_CODE = 1;
private FirebaseListAdapter<ChatMessage> adapter;
RelativeLayout chat_activity_main;
FloatingActionButton fab;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == (R.id.menu_signout))
{
AuthUI.getInstance().signOut( this ).addOnCompleteListener( new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Snackbar.make( chat_activity_main, "You have been signed out.", Snackbar.LENGTH_SHORT).show();
finish();
}
} );
}
return true;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate( R.menu.chat_main_menu, menu );
return true;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult( requestCode, resultCode, data );
if (requestCode == SIGN_IN_REQUEST_CODE)
{
if(resultCode == RESULT_OK)
{
Snackbar.make( chat_activity_main, "Succesfully signed in. Welcome!", Snackbar.LENGTH_SHORT).show();
displayChatMessage();
}
else {
Snackbar.make( chat_activity_main, "We couldn't sign you in. Please try again!", Snackbar.LENGTH_SHORT).show();
finish();
}
}
}
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.chat_activity_main );
chat_activity_main = (RelativeLayout) findViewById( R.id.chat_activity_main );
fab = (FloatingActionButton) findViewById( R.id.fab );
fab.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View view) {
EditText input = (EditText)findViewById( R.id.input );
FirebaseDatabase.getInstance().getReference().push().setValue( new ChatMessage(input.getText().toString(),
FirebaseAuth.getInstance().getCurrentUser().getEmail()));
input.setText( "" );
}
} );
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
startActivityForResult( AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE );
} else {
Snackbar.make( chat_activity_main, "Welcome" + FirebaseAuth.getInstance().getCurrentUser().getEmail(), Snackbar.LENGTH_SHORT ).show();
//Load Content
displayChatMessage();
}
}
private void displayChatMessage() {
ListView listofMessage = (ListView) findViewById( R.id.list_of_messages );
adapter = new FirebaseListAdapter<ChatMessage>(this,ChatMessage.class,R.layout.chat_list_item,FirebaseDatabase.getInstance().getReference()) {
#Override
protected void populateView(View v, ChatMessage model, int position) {
//Get references to the views of chat_list_item.xml
TextView messageText, messageUser, messageTime;
messageText = (TextView) v.findViewById( R.id.message_text );
messageUser = (TextView) v.findViewById( R.id.message_user );
messageTime = (TextView) v.findViewById( R.id.message_time );
messageText.setText( model.getMessageText() );
messageUser.setText( model.getMessageUser() );
messageTime.setText( DateFormat.format( "dd-mm-yyyy (HH:MM:SS)",model.getMessageTime() ) );
}
};
listofMessage.setAdapter( adapter );
}
}
Gradle Build Module:App
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.aids.a09application"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
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.google.firebase:firebase-core:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.google.android.gms:play-services-maps:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0' // ADDED
compile 'com.google.android.gms:play-services-auth:11.2.0' // ADDED
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
compile 'com.firebaseui:firebase-ui:2.3.0'
}
apply plugin: 'com.google.gms.google-services'
I had a similar problem while reading/writing to firebase database this small change worked for me. Try removing unnecessary firebase dependencies and make sure you use the same version for all the firebase dependencies for those that you use. In my case I changed my firebase dependencies from:
implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.0'
to these:
implementation 'com.google.firebase:firebase-firestore:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
I'm sure you might have spent a lot of time trying to fix this. Might as well turn out worth a shot :)

My android studio project works finely on lollipop but crashes while testing on kitkat devices

My android studio project works finely on lollipop but crashes while testing on kitkat devices. it has a material view pager and while opening activity that has material view pager the app just force close on kit kat device.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.production.iedc.helo, PID: 12711
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.production.iedc.helo/com.production.iedc.helo.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:310)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:253)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.production.iedc.helo.MainActivity.onCreate(MainActivity.java:80)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
at dalvik.system.NativeStart.main(Native Method) 
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.production.iedc.helo"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
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 ('com.github.florent37:materialviewpager:1.0.8#aar'){
transitive=true
}
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'com.github.paolorotolo:appintro:3.4.0'
compile 'com.android.support:multidex:1.0.0'
}
Main activity
package com.production.iedc.helo;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.media.Image;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toolbar;
import com.github.florent37.materialviewpager.MaterialViewPager;
import com.squareup.picasso.Picasso;
public class MainActivity extends ActionBarActivity {
MaterialViewPager materialViewPager;
View headerLogo;
ImageView headerLogoContent;
DrawerLayout mDrawer;
ActionBarDrawerToggle mDrawerToggle;
android.support.v7.widget.Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
// Declare a new thread to do a preference check
Thread t = new Thread(new Runnable() {
#Override
public void run() {
// Initialize SharedPreferences
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
// Create a new boolean and preference and set it to true
boolean isFirstStart = getPrefs.getBoolean("firstStart", true);
// If the activity has never started before...
if (isFirstStart) {
// Launch app intro
Intent i = new Intent(MainActivity.this, DefaultIntro.class);
startActivity(i);
// Make a new preferences editor
SharedPreferences.Editor e = getPrefs.edit();
// Edit preference to make it false because we don't want this to run again
e.putBoolean("firstStart", false);
// Apply changes
e.apply();
}
}
});
// Start the thread
t.start();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//4 onglets
final int tabCount = 4;
//les vues définies dans #layout/header_logo
headerLogo = findViewById(R.id.headerLogo);
headerLogoContent = (ImageView) findViewById(R.id.headerLogoContent);
//le MaterialViewPager
this.materialViewPager = (MaterialViewPager) findViewById(R.id.materialViewPager);
toolbar = materialViewPager.getToolbar();
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (toolbar != null) {
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(true);
}
}
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
mDrawer.setDrawerListener(mDrawerToggle);
materialViewPager.getViewPager().setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {
#Override
public Fragment getItem(int position) {
//je créé pour chaque onglet un RecyclerViewFragment
return RecyclerViewFragment.newInstance();
}
#Override
public int getCount() {
return 4;
}
//le titre à afficher pour chaque page
#Override
public CharSequence getPageTitle(int position) {
switch (position % 4) {
case 0:
return "ACADEMICS";
case 1:
return "NEWS FEEDS";
case 2:
return "EVENTS";
case 3:
return "MISC";
default:
return "Page " + position;
}
}
int oldItemPosition = -1;
#Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
//seulement si la page est différente
if (oldItemPosition != position) {
oldItemPosition = position;
//définir la nouvelle couleur et les nouvelles images
Drawable imageUrl = null;
int color = Color.BLACK;
Drawable newDrawable = null;
switch (position) {
case 0:
imageUrl = getResources().getDrawable(R.drawable.academics);
color = getResources().getColor(R.color.cyan);
newDrawable = getResources().getDrawable(R.drawable.earth);
break;
case 1:
imageUrl = getResources().getDrawable(R.drawable.newsfeeds);
color = getResources().getColor(R.color.red);
newDrawable = getResources().getDrawable(R.drawable.tennis);
break;
case 2:
imageUrl = getResources().getDrawable(R.drawable.events);
color = getResources().getColor(R.color.green);
newDrawable = getResources().getDrawable(R.drawable.evennt);
break;
case 3:
imageUrl = getResources().getDrawable(R.drawable.misc);
color = getResources().getColor(R.color.lime);
newDrawable = getResources().getDrawable(R.drawable.light);
break;
}
//puis modifier les images/couleurs
int fadeDuration = 400;
materialViewPager.setColor(color, fadeDuration);
materialViewPager.setImageDrawable(imageUrl, fadeDuration);
toggleLogo(newDrawable,color,fadeDuration);
}
}
});
//permet au viewPager de garder 4 pages en mémoire (à ne pas utiliser sur plus de 4 pages !)
this.materialViewPager.getViewPager().setOffscreenPageLimit(tabCount);
//relie les tabs au viewpager
this.materialViewPager.getPagerTitleStrip().setViewPager(this.materialViewPager.getViewPager());
}
private void toggleLogo(final Drawable newLogo, final int newColor, int duration){
//animation de disparition
final AnimatorSet animatorSetDisappear = new AnimatorSet();
animatorSetDisappear.setDuration(duration);
animatorSetDisappear.playTogether(
ObjectAnimator.ofFloat(headerLogo, "scaleX", 0),
ObjectAnimator.ofFloat(headerLogo, "scaleY", 0)
);
//animation d'apparition
final AnimatorSet animatorSetAppear = new AnimatorSet();
animatorSetAppear.setDuration(duration);
animatorSetAppear.playTogether(
ObjectAnimator.ofFloat(headerLogo, "scaleX", 1),
ObjectAnimator.ofFloat(headerLogo, "scaleY", 1)
);
//après la disparition
animatorSetDisappear.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//modifie la couleur du cercle
((GradientDrawable) headerLogo.getBackground()).setColor(newColor);
//modifie l'image contenue dans le cercle
headerLogoContent.setImageDrawable(newLogo);
//démarre l'animation d'apparition
animatorSetAppear.start();
}
});
//démarre l'animation de disparition
animatorSetDisappear.start();
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
return mDrawerToggle.onOptionsItemSelected(item) ||
super.onOptionsItemSelected(item);
}
}
Activitylayout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.florent37.materialviewpager.MaterialViewPager
android:id="#+id/materialViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:viewpager_logo="#layout/header_logo"
app:viewpager_pagerTitleStrip="#layout/material_view_pager_pagertitlestrip_newstand"
app:viewpager_logoMarginTop="100dp"
app:viewpager_color="#color/colorPrimary"
app:viewpager_headerHeight="200dp"
app:viewpager_headerAlpha="0.6"
app:viewpager_hideLogoWithFade="false"
app:viewpager_hideToolbarAndTitle="true"
app:viewpager_enableToolbarElevation="true"
app:viewpager_parallaxHeaderFactor="1.5"
app:viewpager_headerAdditionalHeight="20dp"
app:viewpager_displayToolbarWhenSwipe="true"
app:viewpager_transparentToolbar="true"
app:viewpager_animatedHeaderImage="true"
/>
<include layout="#layout/drawer" />
</android.support.v4.widget.DrawerLayout>
you should change the inheritance of java use
ActionBarActivity
to
Activity
and leave the dialog theme in the manifest as it is. i think you will not have the problem.

MultiDex stopped working Android

last night I was working on my app, initially I already reached my 64k limit so have had multidex for sometime now, sometimes it does fail and gives me a ClassNotFoundException but all I do is recompile my code and it works, if it fails I restart my computer but this time it is a different case, MultiDex seems to be excluding one of my classes which is funny because it was working until it suddenly stop, what it is doing it is excluding my EnhancedGallery.class which am using as my start activity, if I change to some other activity as start activity in manifest the App works until I try to run EnhancedGallery below are my Gradle Configurations
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "aubry.chromio.com.dressup"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
sourceSets { main { res.srcDirs = ['src/main/res', ' src/main/res/layout_land'] } }
dexOptions {
preDexLibraries = false
javaMaxHeapSize "2g"
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex'
// dx.additionalParameters += "--main-dex- list=$projectDir/dexFiles".toString()
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.twitter.sdk.android:twitter:1.6.0#aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.commit451:PhotoView:1.2.4'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.wang.avi:library:1.0.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.commonsware.cwac:camera:0.6.+'
compile project(':android-support-multidex')
compile 'com.android.support:support-v13:23.1.0'
compile 'com.android.support:palette-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.github.ozodrukh:CircularReveal:1.1.0'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
}
My App.class where I give gradle my app Context
import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
public class App extends Application {
private static App instance;
#Override public void onCreate() {
super.onCreate();
instance = this;
}
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
public static App get() {
return instance;
}
}
My Middle level Gradle file:
configurations.create("default")
artifacts.add("default", file('android-support-multidex.jar'))
And My top Level Gradle File:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// The Fabric Gradle plugin uses an open ended version to
// react quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My error Report:
1-14 09:25:49.430 30154-30154/aubry.chromio.com.dressup E/dalvikvm:
Could not find class 'android.support.v4.app.
NotificationCompat$Builder', referenced from method
com.google.android.gms.common.GooglePlayServicesUtil.zza
11-14 09:25:49.431 30154-30154/aubry.chromio.com.dressup
E/dalvikvm: Could not find class 'android.support.v4.app.FragmentActivity',
referenced from method
com.google.android.gms.common.GooglePlayServicesUtil.zza
11-14 09:25:49.432 30154-30154/aubry.chromio.com.dressup E/dalvikvm: Could not
find class 'android.support.v4.app.FragmentActivity', referenced from method
com.google.android.gms.common.GooglePlayServicesUtil.zza
11-14 09:25:49.442 30154-30154/aubry.chromio.com.dressup E/dalvikvm: Could not
find class 'android.app.AppOpsManager', referenced from method
com.google.android.gms.common.GooglePlayServicesUtil.zzb
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
FATAL EXCEPTION: main
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{aubry.chromio.com.dressup/aubry.chromio.com.dressup.activities.Enhan cedGallery}: java.lang.ClassNotFoundException: Didn't find class
"aubry.chromio.com.dressup.activities.EnhancedGallery" on path:
DexPathList[[zip file "/data/app/aubry.chromio.com.dressup-
1.apk"],nativeLibraryDirectories=[/data/app-lib/aubry.chromio.com.dressup-1,
/vendor/lib, /system/lib]]
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.app.ActivityThread.access$600(ActivityThread.java:162)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.os.Handler.dispatchMessage(Handler.java:107)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.os.Looper.loop(Looper.java:194)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at android.app.ActivityThread.main(ActivityThread.java:5371)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at java.lang.reflect.Method.invokeNative(Native Method)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at java.lang.reflect.Method.invoke(Method.java:525)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at dalvik.system.NativeStart.main(Native Method)
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
Caused by: java.lang.ClassNotFoundException: Didn't find class
"aubry.chromio.com.dressup.activities.EnhancedGallery" on path:
DexPathList[[zip file "/data/app/aubry.chromio.com.dressup-
1.apk"],nativeLibraryDirectories=[/data/app-lib/aubry.chromio.com.dressup-1,
/vendor/lib, /system/lib]]
11-14 09:25:49.518 30154-30154/aubry.chromio.com.dressup E/AndroidRuntime:
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
And lastly my EnhancedGallery Class
import android.content.Context;
import android.database.Cursor;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import java.util.HashSet;
import java.util.Set;
import #####.chromio.com.#####.R;
import #####.chromio.com.#####.polypicker.model.Image;
import #####.chromio.com.#####.polypicker.utils.ImageInternalFetcher;
public class EnhancedGallery extends AppCompatActivity implements
View.OnScrollChangeListener{
public ImageInternalFetcher mImageFetcher;
private ImageGalleryAdapter mGalleryAdapter;
private Set<Image> mSelectedImages;
Display display;
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enhanced_gallery);
toolbar = (Toolbar) findViewById(R.id.toolbar_transparent);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGalleryAdapter = new ImageGalleryAdapter(this);
GridView galleryGridView = (GridView)findViewById(R.id.pp__gallery_grid);
mSelectedImages = new HashSet<Image>();
mImageFetcher = new ImageInternalFetcher(this, 500);
Cursor imageCursor = null;
try {
final String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.ORIENTATION};
final String orderBy = MediaStore.Images.Media.DATE_ADDED + " DESC";
imageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
while (imageCursor.moveToNext()) {
Uri uri = Uri.parse(imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA)));
int orientation = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION));
mGalleryAdapter.add(new Image(uri, orientation));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(imageCursor != null && !imageCursor.isClosed()) {
imageCursor.close();
}
}
galleryGridView.setAdapter(mGalleryAdapter);
galleryGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Image image = mGalleryAdapter.getItem(i);
if (!containsImage(image)) {
//addImage(image);
} else {
//removeImage(image);
}
// refresh the view to
// mGalleryAdapter.getView(i, view, adapterView);
mGalleryAdapter.notifyDataSetChanged();
}
});
}
#Override
public void onScrollChange(View view, int i, int i1, int i2, int i3) {
toolbar.setAlpha(getAlphaforActionBar(view.getScrollY()));
}
private int getAlphaforActionBar(int scrollY) {
int minDist = 0,maxDist = 650;
if(scrollY>maxDist){
return 255;
}
else if(scrollY<minDist){
return 0;
}
else {
int alpha = 0;
alpha = (int) ((255.0/maxDist)*scrollY);
return alpha;
}
}
class ViewHolder {
ImageView mThumbnail;
// This is like storing too much data in memory.
// find a better way to handle this
Image mImage;
}
public class ImageGalleryAdapter extends ArrayAdapter<Image> {
public ImageGalleryAdapter(Context context) {
super(context, 0);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.enhanced_gallery_adapter, null);
holder = new ViewHolder();
holder.mThumbnail = (ImageView) convertView.findViewById(R.id.pp__thumbnail_image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Image image = getItem(position);
boolean isSelected = containsImage(image);
convertView.setForeground(isSelected ? getResources().getDrawable(R.drawable.gallery_photo_selected) : null);
if (holder.mImage == null || !holder.mImage.equals(image)) {
mImageFetcher.loadImage(image.mUri, holder.mThumbnail);
holder.mImage = image;
}
return convertView;
}
}
public boolean containsImage(Image image) {
return mSelectedImages.contains(image);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_settings:
return true;
}
return super.onOptionsItemSelected(item);
}
}
It has been a hustle, I finally fix it, or should I say found a way of bypassing it, since other classes were working I just created another class and copy pasted all my lines of code to the new class and it worked, I do not know the attachment between MultiDex and my EnhancedGallery class yet.

Categories

Resources