下载并安装更新后的 Android 应用程序 ClassNotFoundException

标签 android reinstall

我有一个带有自定义应用程序类的安卓应用程序。

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Utils.isThereUpdatedVersion(this);
    }
}

isThereUpdatedVersion 函数询问一个 php 页面是。我的应用程序有一个新版本可用,并且有一个按钮可以转到另一个 Activity ,按钮可以下载并安装新版本。

我在 list 中添加了 android:name 属性

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name=".application.MyApplication">

当我通过 Android Studio 运行我的应用程序时,该应用程序运行完美。有没有新版本,我可以下载并安装它。但在安装后,我打开应用程序时出现此错误,应用程序崩溃了。

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.andre_jacq_ing.preleveurgmail, PID: 2915
    java.lang.RuntimeException: Unable to instantiate application com.andre_jacq_ing.preleveurgmail.application.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.andre_jacq_ing.preleveurgmail.application.MyApplication" on path: DexPathList[[zip file "/data/app/com.andre_jacq_ing.preleveurgmail-1/base.apk"],nativeLibraryDirectories=[/data/app/com.andre_jacq_ing.preleveurgmail-1/lib/arm64, /system/lib64, /vendor/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:839)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5855)
        at android.app.ActivityThread.-wrap3(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1718)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6688)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.andre_jacq_ing.preleveurgmail.application.MyApplication" on path: DexPathList[[zip file "/data/app/com.andre_jacq_ing.preleveurgmail-1/base.apk"],nativeLibraryDirectories=[/data/app/com.andre_jacq_ing.preleveurgmail-1/lib/arm64, /system/lib64, /vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1000)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:828)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5855) 
        at android.app.ActivityThread.-wrap3(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1718) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6688) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 

有人可以帮我解决这个问题吗?

编辑

我在我的服务器上调用一个 URL,将我重定向到我的 .apk,我使用此代码:

URL url = new URL(arg0[0]);
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();

            int lenghtOfFile = c.getContentLength();

            String PATH = "/mnt/sdcard/Download/";
            File file = new File(PATH);
            file.mkdirs();
            File outputFile = new File(file, "app.apk");
            if(outputFile.exists()){
                outputFile.delete();
            }
            FileOutputStream fos = new FileOutputStream(outputFile);

            InputStream is = c.getInputStream();

            byte[] buffer = new byte[1024];
            int count;
            long total = 0;
            while ((count = is.read(buffer)) != -1) {
                total += count;
                fos.write(buffer, 0, count);
                publishProgress((int) (total * 100 / lenghtOfFile));
            }
            fos.close();
            is.close();

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            context.startActivity(intent);

最佳答案

其实是因为 Android Studio Instant Run。我只是禁用它,它就像一个魅力。

尽管感谢您的帮助。

关于下载并安装更新后的 Android 应用程序 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44065906/

相关文章:

java - fragment 未附加到 Activity,在 onResume 中

java - 如何在 Android Studio 中调试应用程序时使用 "Step Into"或 "Step Over"代码?

java - 为什么我的 LinearLayout 表现得像 null

android - ActionBarSherlock + Google Maps API v2 重复 ID

visual-studio - 在 Windows 上卸载 Xamarin

java - com.github.bumptech.glide :glide making app crash

package - 如何重新安装rpm包?

启动 Eclipse 时出现 java.lang.ClassNotFoundException

ios - ios Keychain 是否适合我的 IAP 问题?