与Unity Project集成到Android Native时出现通货膨胀错误

时间:2018-10-29 04:16:58

标签: android unity3d

我尝试通过引用https://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a将Unity Project集成到Android Studio Project中。 我可以在调试模式下平稳运行,但是当我为发布模式运行/构建apk时,出现了膨胀错误。

10-29 12:02:10.452 28683-28683/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.weeswares.nativeandroid, PID: 28683
                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.weeswares.nativeandroid/com.weeswares.nativeandroid.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.ActionBarContainer
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2796)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867)
                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570)
                                                   at android.os.Handler.dispatchMessage(Handler.java:105)
                                                   at android.os.Looper.loop(Looper.java:156)
                                                   at android.app.ActivityThread.main(ActivityThread.java:6595)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
                                                Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.v7.widget.ActionBarContainer
                                                Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.v7.widget.ActionBarContainer
                                                Caused by: java.lang.reflect.InvocationTargetException
                                                   at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:656)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:798)
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                   at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:406)
                                                   at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
                                                   at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                   at com.weeswares.nativeandroid.MainActivity.onCreate(MainActivity.java:19)
                                                   at android.app.Activity.performCreate(Activity.java:6910)
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2749)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867)
                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570)
                                                   at android.os.Handler.dispatchMessage(Handler.java:105)
                                                   at android.os.Looper.loop(Looper.java:156)
                                                   at android.app.ActivityThread.main(ActivityThread.java:6595)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
                                                Caused by: java.lang.NoSuchMethodError: No static method setBackground(Landroid/view/View;Landroid/graphics/drawable/Drawable;)V in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.weeswares.nativeandroid-1/base.apk:classes14.dex)
                                                   at android.support.v7.widget.ActionBarContainer.<init>(ActionBarContainer.java:64)
                                                   at java.lang.reflect.Constructor.newInstance0(Native Method) 
                                                   at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:656) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:798) 
                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738) 
                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:869) 
                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:377) 
                                                   at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:406) 
                                                   at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323) 
                                                   at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                   at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                                                   at com.weeswares.nativeandroid.MainActivity.onCreate(MainActivity.java:19) 
                                                   at android.app.Activity.performCreate(Activity.java:6910) 
                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2749) 
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867) 
                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                   at android.os.Looper.loop(Looper.java:156) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:6595) 
                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) 

这是我的Android项目Gradle文件。

apply plugin: 'com.android.application'

android {

    compileSdkVersion 27
    defaultConfig {
        applicationId "com.weeswares.nativeandroid"
        minSdkVersion 24
        targetSdkVersion 27
        multiDexEnabled = true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            //minifyEnabled false
            //proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
            //signingConfig signingConfigs.config
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    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 project(':PGame-debug')
}

这是我争取统一项目的条件。

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

allprojects {
   repositories {
      flatDir {
        dirs 'libs'
      }
       google()
   }
}

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'NatCam', ext:'aar')
    compile(name: 'NatCamRenderPipeline', ext:'aar')
    compile(name: 'android-beacon-library', ext:'aar')
    compile(name: 'ibeacon', ext:'aar')
    compile 'com.android.support:appcompat-v7:27.1.1'
}

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.2'
    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ndk {
            abiFilters 'armeabi-v7a', 'x86'
        }
    }
    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress '.unity3d', '.ress', '.resource', '.obb','sp_human_face_68_for_mobile.dat'
    }
    buildTypes {
        release {
//          minifyEnabled false
//          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.weeswares.nativeandroid.MainActivity">


    <Button
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:id="@+id/btnPGame"
        android:text="PGame"/>

</RelativeLayout>

我进行了很多搜索,但找不到正确的方法。感谢您提前帮助我。

0 个答案:

没有答案