无法启动活动,并且应用程序崩溃了
我尝试添加一些依赖项,但无法合并 清单
C1
它显示以下日志,我无法理解 我是否必须添加一些依赖项才能使其正常工作, 我可以在android设备上运行该应用,但是当我尝试启动 activityit崩溃了
package com.example.penaliz;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.vision.CameraSource;
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.text.TextBlock;
import com.google.android.gms.vision.text.TextRecognizer;
import java.io.IOException;
public class camActivity extends AppCompatActivity {
SurfaceView cameraView;
String s1;
TextView textView;
CameraSource cameraSource;
final int RequestCameraPermissionID = 1001;
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case RequestCameraPermissionID: {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
return;
}
try {
cameraSource.start(cameraView.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
}
break;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cam);
cameraView = (SurfaceView) findViewById(R.id.surface_view);
textView = (TextView) findViewById(R.id.text_view);
TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
if (!textRecognizer.isOperational()) {
Log.w("MainActivity", "Detector dependencies are not yet available");
} else {
cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1280, 1024)
.setRequestedFps(2.0f)
.setAutoFocusEnabled(true)
.build();
cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(camActivity.this,
new String[]{Manifest.permission.CAMERA},
RequestCameraPermissionID);
return;
}
cameraSource.start(cameraView.getHolder());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
cameraSource.stop();
}
});
textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
@Override
public void release() {
}
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
final SparseArray<TextBlock> items = detections.getDetectedItems();
if(items.size() != 0)
{
textView.post(new Runnable() {
@Override
public void run() {
StringBuilder stringBuilder = new StringBuilder();
for(int i =0;i<items.size();++i)
{
TextBlock item = items.valueAt(i);
stringBuilder.append(item.getValue());
stringBuilder.append("\n");
}
textView.setText(stringBuilder.toString());
}
});
Button btn = (Button) findViewById(R.id.btn1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
s1=textView.getText().toString();
Intent i = new Intent(camActivity.this,Affance.class);
i.putExtra("message",s1);
startActivity(i);
}
});
}
}
});
}
}
}
该如何使该活动正常工作? 这是依赖文件
'''`E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.penaliz, PID: 31333
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zztl;
at com.google.android.gms.vision.internal.client.zza.zzcls(Unknown Source:13)
at com.google.android.gms.vision.text.internal.client.zzg.<init>(Unknown Source:7)
at com.google.android.gms.vision.text.TextRecognizer$Builder.build(Unknown Source:6)
at com.example.penaliz.camActivity.onCreate(camActivity.java:63)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1838)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6715)
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:911)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zztl" on path: DexPathList[[zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/base.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_resources_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/lib/arm64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.android.gms.vision.internal.client.zza.zzcls(Unknown Source:13)
at com.google.android.gms.vision.text.internal.client.zzg.<init>(Unknown Source:7)
at com.google.android.gms.vision.text.TextRecognizer$Builder.build(Unknown Source:6)
at com.example.penaliz.camActivity.onCreate(camActivity.java:63)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1838)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6715)
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:911)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.penaliz-Y6sjCxlQmwAdFU1Jik2q8A==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:354)
at dalvik.system.DexFile.<init>(DexFile.java:101)
at dalvik.system.DexFile.<init>(DexFile.java:75)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
E/AndroidRuntime: at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:810)
at android.app.LoadedApk.getResources(LoadedApk.java:1032)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2346)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5789)
at android.app.ActivityThread.access$1200(ActivityThread.java:208)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1680)
... 6 more`
这是清单
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.penaliz"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true;
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-storage:16.0.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-vision:9.8.0'
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:0)
该错误可能是因为这些依赖项具有不同的版本号:
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-storage:16.0.5'
因此请尝试将其更改为以下内容:
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.google.firebase:firebase-core:16.1.0'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.google.firebase:firebase-storage:16.1.0'
还要在您的依赖项中添加implementation 'com.android.support:multidex:1.0.3'
。