java.lang.NoClassDefFoundError:解析失败:Landroidx/appcompat/app/AppCompatActivity;

问题描述 投票:0回答:2

我有带有 android studio 插件的 Unity 应用程序,当我按下按钮时,它会在我的手机上加载 Android 相机应用程序...这里 java 类:

 import android.content.Intent;
 import android.os.Bundle;
 import android.provider.MediaStore;
 import androidx.appcompat.app.AppCompatActivity;


 public class LoadAndroidApp extends AppCompatActivity 
 {
     @Override
     protected void onCreate(Bundle savedInstanceState) 
   {

     super.onCreate(savedInstanceState);
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     startActivity(intent);
   }
 }

这是我的构建gradle:

    apply plugin: 'com.android.library'

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
    minSdkVersion 24
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    consumerProguardFiles "consumer-rules.pro"
}

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-alpha04'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'androidx.test.ext:junit:1.1.2'
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

当我启动 Unity 应用程序时,它不会崩溃,但我在 logcat 中遇到此错误:

 2021-04-27 18:45:26.327 27678-27700/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity;
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity;
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
    at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:241)
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
 Caused by: java.lang.ClassNotFoundException: androidx.appcompat.app.AppCompatActivity
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 
    at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 
    at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 
    at android.os.Handler.dispatchMessage(Handler.java:103) 
    at android.os.Looper.loop(Looper.java:241) 
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 
  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <00000000000000000000000000000000>:0 

请帮助,我需要一些反馈...我读到发生这种情况是因为 aar 文件不包含我们在 gradle 文件中添加的外部依赖项,但在创建插件时我没有错误...请帮忙...提前谢谢你。

java android android-studio logcat
2个回答
2
投票

当您编译插件时,它不包含“androidx.appcompat.app.AppCompatActivity”,您必须将该包添加到您的 Plugin/Android 文件夹中。有两种方法可以解决这个问题;

1-Unity 的外部依赖管理器!该插件有助于添加外部依赖项。

2-您可以在Android开发者网站上找到依赖项.jar或.aar。

我推荐第一个选项。因为它还处理 cocoapods 依赖项。

如果您不需要任何依赖项,请仅使用“Activity”扩展您的类。如果您的函数包含在 Activity 类中,则无需添加任何依赖项。


0
投票

对于我收到此错误,请帮助我初始化 12-24 23:09:10.094 4598 5706 我统一:仪表板:initilizeAndroidPlugin() 12-24 23:09:10.094 4598 5706 我统一: 12-24 23:09:10.097 4598 5706 I Unity:调用添加时出错:UnityEngine.AndroidJavaException:java.lang.NoClassDefFoundError:解析失败:Landroidx/fragment/app/Fragment; 12-24 23:09:10.097 4598 5706 I Unity:在 UnityEngine.AndroidJNISafe.CheckException () [0x00000] 中 <00000000000000000000000000000000>:0 12-24 23:09:10.097 4598 5706 I Unity:在UnityEngine.AndroidJNISafe.FindClass(System.String名称)[0x00000]中<00000000000000000000000000000000>:0 12-24 23:09:10.097 4598 5706 I Unity:在UnityEngine.AndroidJavaObject._AndroidJavaObject(System.String className,System.Object [] args)[0x00000]中<00000000000000000000000000000000>:0 12-24 23:09:10.097 4598 5706 I Unity:在dashboard.initilizeAndroidPlugin()[0x00000]中<00000000000000000000000000000000>:0

© www.soinside.com 2019 - 2024. All rights reserved.