我有一个带有自定义Application类的Android应用程序。
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Utils.isThereUpdatedVersion(this);
}
}
isThereUpdatedVersion 函数询问php页面是什么。我的应用程序有一个新版本,有一个按钮可以转到另一个活动,并带有一个按钮,可以下载安装新版本。
我将 android:name 属性添加到我的Manifest
<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);
答案 0 :(得分:3)
嗯,实际上是因为Android Studio的即时运行。我只是禁用它,它就像一个魅力。
尽管感谢您的帮助。
答案 1 :(得分:0)
如果您的包名称正确,请尝试清理您的项目并卸载该应用程序。然后重新安装该应用程序。