我得到这些错误在编译我的项目对于解决DEX档案的错误,我想从我的项目目录中删除文件夹.gradle但仍然不解决问题。
这是我的gradle项目文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我的应用程序文件的gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.spars.myapplication"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.razorpay:checkout:1.4.5'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.firebaseui:firebase-ui:3.0.0'
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
//added part xxx
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '27.1.1'
}
}
}
}
这是我的项目中的Java文件:
package com.example.xxx.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseListAdapter;
import com.firebase.ui.database.FirebaseListOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
public class MainActivity extends AppCompatActivity {
ListView lv;
FirebaseListAdapter adapter;
FirebaseDatabase database;
DatabaseReference ref;
TextView t;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,Payment.class);
startActivity(i);
}
});
database = FirebaseDatabase.getInstance();
ref = database.getReference();
lv=(ListView)findViewById(R.id.listView);
Query query = FirebaseDatabase.getInstance().getReference().child("martyrs");
FirebaseListOptions<martyrs> options = new FirebaseListOptions.Builder<martyrs>()
.setLayout(R.layout.martyrs)
.setLifecycleOwner(MainActivity.this)
.setQuery(query,martyrs.class)
.build();
adapter = new FirebaseListAdapter(options) {
@Override
protected void populateView(View v, Object model, int position) {
//ImageView img = v.findViewById(R.id.);
TextView name = v.findViewById(R.id.name);
TextView age = v.findViewById(R.id.age);
martyrs mt = (martyrs) model;
name.setText(mt.getName().toUpperCase());
age.setText(mt.getAge().toUpperCase());
}
};
lv.setAdapter(adapter);
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
最后,我发现了以下错误:
任何人都可以帮助吗?
更改
implementation 'com.firebaseui:firebase-ui:3.0.0'
至
implementation 'com.firebaseui:firebase-ui:3.3.1'
implementation 'android.arch.lifecycle:extensions:1.1.1
这解决了这个问题对我来说:
请您尝试一下,并给予反馈。
更新1:
尝试添加以下代码行的app.gradle
implementation "android.arch.lifecycle:extensions:1.0.0"
// Multidex
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.google.firebase:firebase-analytics:15.0.0'