我在平板电脑/手机上使用android 4.4和8.1(api level 19& 27)运行我的应用时遇到错误

时间:2018-01-11 11:03:57

标签: android

当我在android 4.4设备上运行它时会发生这个ClassNotFound异常,我想知道它是怎么发生的,因为我已经在我的清单文件下注册了所有活动,但是这个错误仍然会再次发生,这让我很困惑。 请任何人都可以告诉我我的代码有什么问题:

这是错误:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.Forewarn.ForewarnApp.activities.Splash Activity" on path: DexPathList[[zip file "/data/app/com.Forewarn.ForewarnApp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.Forewarn.ForewarnApp-2, /system/lib]]

这是显而易见的:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.Forewarn.ForewarnApp">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.WRITE_CALL_LOG" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />

    <uses-permission
        android:name="android.permission.MODIFY_PHONE_STATE"
        tools:ignore="ProtectedPermissions" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />

    <configuration>
        <release>
            true
        </release>
    </configuration>

    <permission
        android:name="com.Forewarn.ForewarnApp.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.Forewarn.ForewarnApp.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <application
        android:name=".activities.SoteriaApplication"
        android:allowBackup="false"
        android:icon="@drawable/ic_launcherr"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".activities.SplashActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|screenSize"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity
            android:name=".activities.SignInActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity android:name=".activities.SignUpActivity" />
        <activity android:name=".activities.ForgotPasswordActivity" />
        <activity android:name=".activities.SerachResultsActivity" />
        <activity android:name=".activities.DetailsPageActivity" />
        <activity android:name=".activities.PropertyDetailsActivity" />
        <activity android:name=".activities.BankurptsDetailsActivity" />
        <activity android:name=".activities.SampleActivity" />
        <activity android:name=".activities.ActivityCallLog" />
        <activity android:name=".activities.SettingsActivity" />
        <activity android:name=".activities.VehicleDetailsActivity" />
        <activity android:name=".activities.ResultsActivity" />
        <activity android:name=".activities.OthersActivity" />
        <activity android:name=".activities.NoRecordsActivity" />
        <activity android:name=".activities.MoreRecordsActivity" />
        <activity
            android:name=".activities.CriminalDetailsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity android:name=".activities.CriminalSampleActivity" />
        <activity
            android:name=".activities.OtpActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity android:name=".activities.AddressesDetailsActivity" />
        <activity
            android:name=".activities.PhonesHistoryDetailsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity android:name=".activities.ContactsReaderActivity" />
        <activity
            android:name=".activities.FingerprintTermsAndConditionsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity android:name=".activities.ChangePasswordActivity" />
        <activity
            android:name=".activities.TermsandConditionsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize" />
        <activity android:name=".activities.PdfPasswordActivity"></activity>
    </application>

</manifest>

然后我把我的minsdkversion = 19 maxsdkversion = 27 和错误让Android 8.1.0(api level 27)设备上的应用程序崩溃。

这是我的应用程序类代码:

public class SoteriaApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        AccountUtils.assignContext(this);
        MultiDex.install(this);
    }
}

顺便说一句,我尝试使用即时运行禁用方法:现在我得到验证错误:像这样:

FATAL EXCEPTION: main
                                                                        Process: com.Forewarn.ForewarnApp, PID: 1060
                                                                        java.lang.VerifyError: com/Forewarn/ForewarnApp/activities/SignInActivity
                                                                            at java.lang.Class.newInstanceImpl(Native Method)
                                                                            at java.lang.Class.newInstance(Class.java:1208)
                                                                            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
                                                                            at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:136)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5017)
                                                                            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:779)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                                                                            at dalvik.system.NativeStart.main(Native Method)

4 个答案:

答案 0 :(得分:0)

声音就像Multidex问题一样。在您的应用程序类activities.SoteriaApplication中添加此

  @Override
  protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
  }

app.gradle

android {
 defaultConfig {
      multiDexEnabled true
  }
 dexOptions {
        javaMaxHeapSize "4g"
    }
}

在Gradle中启用Multidex

NB:仅当这是您的自定义应用程序类时才使用android:name=".activities.SoteriaApplication"

还可以尝试清理并重建项目并运行应用程序而无需立即运行。检查问题是否已解决

答案 1 :(得分:0)

Update2 (阅读更新的问题和错误日志后)

我已经看到你有验证者日志,所以让我描述它希望你能得到一些线索。 Here正在进行详细讨论。

  

此错误表示Java虚拟机(JVM)中包含的验证程序检测到一个类文件,尽管格式良好,但它包含某种类型的内部不一致或面临安全问题。

     

VerifyError类扩展了用于的LinkageError类   表示那些错误情况,其中一个类依赖于某些类   其他类和那个类在之后不一致地改变了   汇编。此外,LinkageError类扩展了Error   class,用来表示那些严重的问题   申请不应该抓住。方法可能不会声明此类错误   它的throw子句,因为这些错误都是异常情况   永远不会发生。

     

最后,自1.0版Java以来​​,VerifyError一直存在。

对我来说,这可能就是你的情况。考虑this SO问题并检查您的依赖关系。清理您的项目。甚至重启你的系统。我确实认为这不是正确的清理你的项目。

<强> UPDATE1 我也有同样的问题。我如何解决它是通过在build.gradle文件依赖项中添加以下行。

  

编译'com.android.support:multidex:1.0.2'

然后在我的Application类中,我使用“extends MultiDexApplication”扩展它,我确保在onCreate方法中添加它。 like

public class SoteriaApplication extends MultiDexApplication  {
//Please extend your application class with MultiDexApplication 
@Override
public void onCreate() {
    super.onCreate();
    AccountUtils.assignContext(this);
    MultiDex.install(this);
}}
  

请使用MultiDexApplication类扩展您的应用程序类。

答案 2 :(得分:0)

做一件事 - :

Go to File on top menu->Setting->Build Execution->Instant run->If its enabled then try disabling that.

答案 3 :(得分:0)

如果您已经完成@ A.s.ALI和@Tomin B Azhakathu提到的MultiDex工作,但仍然拥有ClassNotFoundException。然后,您应该查看com.Forewarn.ForewarnApp.activities.SplashActivity中是否有main dex(您可以将APK拖动到Android Studio中并进行确认)。如果com.Forewarn.ForewarnApp.activities.SplashActivitymain dex中,并且仍然抛出异常,请告诉我,谢谢。