Android Studio有自定义类的错误文件路径

时间:2017-10-27 15:43:09

标签: android-studio

我的应用程序有几个自定义类,这些类保存在名为“models”的文件夹中,并通过“com.myname.appname.models.classname”进行访问。直到最近才工作正常,但是当它试图给使用其中一个类的布局充气时突然崩溃了。

我得到的错误如下:

android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class com.myname.appname.ColourCell
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.myname.appname.ColourCell
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myname.appname.ColourCell" on path: DexPathList[...]

所以它正在寻找com.myname.appname.ColourCell而不是com.myname.appname.models.ColourCell

我已经用Google搜索了ClassNotFoundException错误,并找到了以下解决方案,其中任何一个似乎都无效:

  • 启用MultiDex
  • 更新compileSDKVersion
  • 添加'maven'支持
  • 禁用即时运行

当它试图给布局充气时,它仍会因同样的错误而崩溃。

我不知道下一步该尝试什么。我根本不懂gradle - 我一直都在使用它!我在网上找到的解决方案似乎以gradle文件为中心,所以我将它们包含在下面:

应用程式:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    signingConfigs {
        config {
            keyAlias 'xxx'
            keyPassword 'xxx'
            storeFile file('xxx')
            storePassword 'xxx'
        }
    }
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.myname.appname"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 7
        versionName "1.0.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        debug {
            minifyEnabled false
        }
    }
    productFlavors {
        freeConfig {
            applicationId 'com.myname.appname.free'
        }
        paidConfig {
            applicationId 'com.myname.appname.full'
        }
    }
    packagingOptions {

        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'

    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile project(path: ':backend', configuration: 'android-endpoints')
    compile 'com.android.support:appcompat-v7:26.0.0-beta1'
    compile 'com.android.support:design:26.0.0-beta1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.code.findbugs:jsr305:2.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.firebase:firebase-ads:10.0.1'
    compile 'com.firebase:firebase-client-android:2.5.0'
    compile 'com.google.firebase:firebase-core:10.0.1'
    compile 'com.firebaseui:firebase-ui-database:1.1.1'
    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
}

应用程序名:

buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我尝试过清理项目并重建,但没有成功。它运行正常,直到它到达特定的inflate语句并尝试使用它找不到的类。我完全不知道下一步该尝试什么。

1 个答案:

答案 0 :(得分:0)

我有一个脑波并且(通过'重构'菜单选项)将'ColourCell'类移动到AS正在查看的路径。这很有效。然后我能够将它移回(再次通过'重构')到'模型',它仍在工作。