当前位置: 首页 > 知识库问答 >
问题:

Android运行时异常:在路径:DexPathList上找不到类

壤驷高洁
2023-03-14

我从GitHub下载了这段代码,看看是否可以对其进行定制,使其适用于我正在进行的项目。我希望这是我的最后一期,但我完全被这个错误所困住了。我可以构建和运行应用程序,但它在启动时崩溃。

我在这里经历了许多类似的问题,我根据解决方案做出了修改,但它们似乎对我不起作用。我是这方面的新手,如果有任何帮助,我将不胜感激。拜托...任何人。:)

import java.util.regex.Pattern

//apply plugin: 'android'
apply plugin: 'com.android.application'

buildscript {
    repositories {
        //mavenCentral()
        jcenter()
    }

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

ext.multiarch=false

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    for (subproject in getProjectList()) {
        compile project(subproject)
    }

    compile 'com.android.support:multidex:1.0.1'
}

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        useLibrary 'org.apache.http.legacy'
    }

    defaultConfig {
        versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")

        //Enabling Multidex Support
        multiDexEnabled true

        compileSdkVersion 23

        buildToolsVersion "23.0.1"
    }



    if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
        productFlavors {
            armv7 {
                versionCode defaultConfig.versionCode + 2
            ndk {
                    abiFilters "armeabi-v7a", ""
                }
            }
            x86 {
                versionCode defaultConfig.versionCode + 4
                ndk {
                    abiFilters "x86", ""
                }
            }
            all {
                ndk {
                    abiFilters "all", ""
                }
            } 
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

}

task wrapper(type: Wrapper) {
    gradleVersion = '1.12'
}

def getVersionCodeFromManifest() {
    def manifestFile = file(android.sourceSets.main.manifest.srcFile)
    def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
    def matcher = pattern.matcher(manifestFile.getText())
    matcher.find()
    return Integer.parseInt(matcher.group(1))
}

def getProjectList() {
    def manifestFile = file("project.properties")
    def pattern = Pattern.compile("android.library.reference.(\\d+)\\s*=\\s*(.*)")
    def matcher = pattern.matcher(manifestFile.getText())
    def projects = []
    while (matcher.find()) {
      projects.add(":" + matcher.group(2).replace("/",":"))
    }
    return projects
}  
<?xml version='1.0' encoding='utf-8'?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ford.fordcomplince"

    android:hardwareAccelerated="true"
    android:versionCode="1"
    android:versionName="0.1.0">

    <!--
    xmlns:android="http://schemas.android.com/tools"
    xmlns:tools="http://schemas.android.com/apk/res-auto"> -->

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission   android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


    <application
        android:name="android.support.multidex.MultiDexApplication"
        android:hardwareAccelerated="true"
        android:icon="@drawable/iicon"
        android:label="@string/app_name">

        <activity
            android:name=".FordCompliance"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
            android:label="@string/activity_name"
            android:launchMode="singleTop"
            android:theme="@android:style/Theme.Black.NoTitleBar"
            android:windowSoftInputMode="adjustResize">
        <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".EnableMultiDex">

        </activity>

    </application>


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

</manifest>
package com.ford.therightway;

/**
 * Created by SK on 2/20/2017.
 */

import android.support.multidex.MultiDexApplication;

public class EnableMultiDex extends MultiDexApplication{

}

这是我的错误输出-

共有1个答案

姚乐家
2023-03-14

您可以禁用android studio即时运行功能来查看是否仍然出现错误。即时运行可能会导致奇怪的问题

 类似资料: