我第一次使用FCM,并在已有的项目中添加了依赖项。现在当我尝试运行它时,我收到了这个错误:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/location/places/zzi.class
这是我的构建代码:
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'
我在尝试自己解决这个问题时注意到的另一件事是,我取代了
compile 'com.google.firebase:firebase-messaging:9.6.1'
与
compile 'com.google.firebase:firebase-messaging:9.0.0'
之后我的应用程序正常运行。我的应用应返回令牌ID,但它返回null
,然后应用程序崩溃并出现此异常:
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)
这是我的主要代码,它正在调用令牌
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();
}
}
}