简体   繁体   English

Android Studio 2.3.3不会从JAR加载类文件

[英]Android Studio 2.3.3 won't load class file from JAR

I've copied a jar file into my project's libs folder. 我已将一个jar文件复制到项目的libs文件夹中。 Usually it will show me all of the files contained therein. 通常它将向我显示其中包含的所有文件。 For this one JAR file, it won't display the class file embedded inside, but does display a manifest file. 对于这个JAR文件,它不会显示嵌入其中的类文件,但会显示清单文件。

Let's say the jar is custom-unity-activity.jar and the directory structure is com\\custom\\activity\\custom-unity-activity.class. 假设jar为custom-unity-activity.jar,目录结构为com \\ custom \\ activity \\ custom-unity-activity.class。 As far as Android Studio gets is "com.custom" and then goes no further. 就Android Studio而言,它是“ com.custom”,然后就不进一步了。 The compiler also can't resolve symbols defined in the class file, so it definitely isn't reading it in. 编译器也无法解析在类文件中定义的符号,因此绝对不会读入。

I know this jar file is valid, because it has been used successfully under a different build environment. 我知道这个jar文件是有效的,因为它已在其他构建环境下成功使用。

项目截图

It's really hard to import Unity's project into an existing Android Project. 很难将Unity的项目导入现有的Android项目。 The solution is to do it the other way around instead. 解决方案是用另一种方法代替。

Build the Android Studio project as to jar or .arr plugin then place in your Unity project at: <ProjectName>Assets\\Plugins\\Android . 针对jar或.arr插件构建Android Studio项目,然后将其放置在Unity项目中: <ProjectName>Assets\\Plugins\\Android

If you want to load your Android Studio project activity, you must modify the AndroidManifest.xml to let Unity know that then place it at: <ProjectName>Assets\\Plugins\\Android . 如果要加载Android Studio项目活动,则必须修改AndroidManifest.xml以使Unity知道,然后将其放置在: <ProjectName>Assets\\Plugins\\Android

Below is what the XML should look like. 下面是XML的外观。 It will specify the activity name to load and will also tell Unity to allow you to use input events from your Android Studio project otherwise, Unity will steal those events. 它会指定要加载的活动名称,还会告诉Unity允许您使用来自Android Studio项目的输入事件,否则,Unity将窃取这些事件。 The manifest below assumes that the Android Studio activity name is "MainActivity". 下面的清单假定Android Studio活动名称为“ MainActivity”。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.casualcoder.plugin" android:installLocation="auto">

  <uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="19" />

  <supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />

  <application android:icon="@drawable/app_icon" android:label="@string/app_name">

    <activity android:name=".MainActivity"
             android:label="@string/app_name"
             android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      <meta-data android:name="android.app.lib_name" android:value="unity" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
      <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>

    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:screenOrientation="landscape">
      <meta-data android:name="android.app.lib_name" android:value="unity" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    </activity>
      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:screenOrientation="landscape">
      <meta-data android:name="android.app.lib_name" android:value="unity" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    </activity>

  </application>
</manifest>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM