0

I'm using FCM for the first time and I have added the dependencies in my already existing project. Now when I try to run it, I'm getting this error:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/location/places/zzi.class

Here is my build code:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "app.com.example.saeed.fypmerged"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.2.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'    java.lang.NoClassDefFoundError: com.google.firebase.iid.zza
    at com.google.firebase.iid.zzg.zze(Unknown Source)
    at com.google.firebase.iid.zzd.zzbmt(Unknown Source)
    at com.google.firebase.iid.zzd.zzc(Unknown Source)
    at com.google.firebase.iid.zzd.getToken(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceId.getToken(Unknown Source)
    compile files('libs/GenAsync.jar')
}
apply plugin: 'com.google.gms.google-services'

One more thing which I noticed while trying to solve this problem on my own was, I replaced

 compile 'com.google.firebase:firebase-messaging:9.6.1'

with

 compile 'com.google.firebase:firebase-messaging:9.0.0'

after that my app run properly. My app should return the token id, but it is returning null and then the app crashes with this exception:

 FATAL EXCEPTION: pool-2-thread-1

 java.lang.NoClassDefFoundError: com.google.firebase.iid.zza
    at com.google.firebase.iid.zzg.zze(Unknown Source)
    at com.google.firebase.iid.zzd.zzbmt(Unknown Source)
    at com.google.firebase.iid.zzd.zzc(Unknown Source)
    at com.google.firebase.iid.zzd.getToken(Unknown Source)
    at com.google.firebase.iid.FirebaseInstanceId.getToken(Unknown Source)

here Is my main code, which is calling for the token

  public class MainActivity extends AppCompatActivity implements
        AsyncResponse, View.OnClickListener{
    EditText etUsername, etPassword;
    Button btLogin, btn_rest;
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        etUsername = (EditText) findViewById(R.id.etname);
        etPassword = (EditText) findViewById(R.id.etpassword);
        btLogin = (Button) findViewById(R.id.button);
        btLogin.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        HashMap postData = new HashMap();
        postData.put("mobile","android");
        postData.put("txtUsername", etUsername.getText().toString());
        postData.put("txtPassword", etPassword.getText().toString());
        PostResponseAsyncTask task = new PostResponseAsyncTask(this, postData);
        task.execute("http://shahtaj.comxa.com/login.php");

    }

    @Override
    public void processFinish(String result) {
        Log.i("okk", "processFinish: " + result);
        if (result.equals("success")) {
         // HERE I HAVE TO GET THE TOKEN But is returning null
            Log.d(TAG, "Instance ID Token: " + FirebaseInstanceId.getInstance().getToken());

            Toast.makeText(this, "Login success yayy", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(MainActivity.this,MapsActivity.class);
            startActivity(intent);
        }
        else
        {
            Toast.makeText(this, "Login Failed BOOO", Toast.LENGTH_LONG).show();
        }
    }
}
AL.
  • 36,815
  • 10
  • 142
  • 281
shahtaj khalid
  • 476
  • 7
  • 24
  • Try to use both firebase messaging and google play services with version 9.6.1. Update the SDK using the SDK Manager. – Geert Berkers Oct 11 '16 at 18:22
  • And add compile 'com.firebase:firebase-client-android:2.5.2'. to dependencies – Geert Berkers Oct 11 '16 at 18:22
  • @GeertBerkers I tried, and still getting the same exception Process: java.lang.NoClassDefFoundError: com.google.firebase.iid.zza at com.google.firebase.iid.zzg.zze(Unknown Source) – shahtaj khalid Oct 11 '16 at 19:00
  • In your android studio, are you getting the update repository pop-up? if yes then update it and try syncing dependencies again. It may take some time but you should be able to add the latest dependency 9.6.1 – Abhinav Raja Oct 12 '16 at 07:27

0 Answers0