使用支持AndroidAnnotations的崩溃应用程序:appcompat-v7版本23 +

时间:2016-10-07 06:09:56

标签: android android-support-library android-annotations

我使用最新appcompathow to develop a plugin)并尝试将24.2.1更改为targetVersion 24以支持appcompat-v7。但是,使用appcompat-v7:22.2.0版本23+时我的应用程序崩溃了,但是,它在 FATAL EXCEPTION: main Process: ABC, PID: 1275 java.lang.RuntimeException: Unable to start activity ComponentInfo{MyPackage/MyPackage.activities.MainActivity_}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:212) at android.app.ActivityThread.main(ActivityThread.java:5137) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at android.view.LayoutInflater.inflate(LayoutInflater.java:353) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at MyPackage.activities.MainActivity_.setContentView(MainActivity_.java:51) at MyPackage.activities.MainActivity_.onCreate(MainActivity_.java:40) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)  at android.app.ActivityThread.access$800(ActivityThread.java:144)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:212)  at android.app.ActivityThread.main(ActivityThread.java:5137)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)  at dalvik.system.NativeStart.main(Native Method)  Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Must specify unique android:id, android:tag, or have a parent with an id for MyPackage.fragments.MainFragment_ at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2387) at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120) at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:376) at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  at MyPackage.activities.MainActivity_.setContentView(MainActivity_.java:51)  at MyPackage.activities.MainActivity_.onCreate(MainActivity_.java:40)  at android.app.Activity.performCreate(Activity.java:5231)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)  at android.app.ActivityThread.access$800(ActivityThread.java:144)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:212)  at android.app.ActivityThread.main(ActivityThread.java:5137)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:718)  at dalvik.system.NativeStart.main(Native Method)  上正常运行。任何建议都是适当的。以下是我的错误日志:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
...

def PACKAGE_NAME = "MyPackage"
def VERSION_CODE = 1
def VERSION_NAME = "1.0.0"

def AAVersion = '4.1.0'

tasks.withType(JavaCompile) {
  options.encoding = 'UTF-8'
}

buildscript {
  repositories {
    mavenCentral()
    ...
  }
  dependencies {
    // replace with the current version of the Android plugin
    classpath 'com.android.tools.build:gradle:2.2.0'
    // replace with the current version of the android-apt plugin
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    ...
  }
}

apt {
  arguments {
    androidManifestFile variant.outputs[0].processResources.manifestFile
    resourcePackageName PACKAGE_NAME
  }
}

repositories {
  mavenCentral()
  ...
}

android {
  compileSdkVersion 24
  buildToolsVersion "24.0.2"

  defaultConfig {
    applicationId PACKAGE_NAME
    minSdkVersion 14
    targetSdkVersion 24
    versionCode VERSION_CODE
    versionName VERSION_NAME

    // Enabling multidex support.
    multiDexEnabled true
  }

  signingConfigs {
    ...
  }

  buildTypes {
    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
      signingConfig signingConfigs.release
    }
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  packagingOptions {
    ...
  }

  dexOptions {
    ...
  }

  ...
}

dependencies {
  apt "org.androidannotations:androidannotations:$AAVersion"
  compile "org.androidannotations:androidannotations-api:$AAVersion"
  ...
  compile 'com.android.support:appcompat-v7:24.2.1'
  compile 'com.google.android.gms:play-services-maps:9.6.1'
  compile 'com.google.android.gms:play-services-location:9.6.1'
  compile 'com.google.android.gms:play-services-gcm:9.6.1'
  compile 'com.squareup.retrofit2:retrofit:2.1.0'
  compile 'com.squareup.retrofit2:converter-gson:2.1.0'
  compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
  compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
  compile('com.squareup.okhttp3:okhttp:3.2.0') {
    exclude module: 'okhttp'
  }
  compile 'io.reactivex:rxandroid:1.0.1'
  compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
  compile 'com.github.mrmike:ok2curl:0.2.3'
  compile 'de.greenrobot:eventbus:2.4.0'
  compile 'com.android.support:multidex:1.0.1'
  compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
    transitive = true;
  }
}

repositories {
  flatDir {
    dirs 'libs'
  }
}

这是我的傻瓜

< or <

1 个答案:

答案 0 :(得分:0)

因为它是从堆栈跟踪中准备好的,所以问题是你没有在xml布局中为你的Fragment添加任何ID标签,如果它声明了一个实例。有问题的片段是MyPackage.fragments.MainFragment_。这是标准错误,与AndroidAnnotations无关。

<fragment android:name="MyPackage.fragments.MainFragment_"
              android:id="@+id/fragment_id" <!-- Add an ID -->
              android:layout_width="match_parent"
              android:layout_height="match_parent" />