我在Android工作室开发了一个Android应用程序,当我直接从Android工作室运行应用程序它工作正常,但当我生成apk发送到任何设备并安装它应用程序崩溃并给我这个例外
RuntimeException: Unable to instantiate application com.projects.epic.khosomaty.MyApplication: java.lang.ClassNotFoundException: Didn't find class "com.projects.epic.khosomaty.MyApplication" on path: DexPathList[[zip file "/data/app/com.projects.epic.khosomaty-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
这是导致异常的类
public class MyApplication extends Application {
private static MyApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized MyApplication getInstance() {
return mInstance;
}
public void setConnectivityListener(ConnectivityReceiver.ConnectivityReceiverListener listener) {
ConnectivityReceiver.connectivityReceiverListener = listener;
}
}
这是清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.projects.epic.khosomaty">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name="com.projects.epic.khosomaty.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="A............o" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/white" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".Activities.Login"
android:label="@string/log_in_tittle"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.SignUp"
android:label="@string/sign_up_tittle" />
<activity
android:name=".Activities.ChangePassword"
android:label="@string/customer_change_password_tittle" />
<activity
android:name=".Activities.MerchantDetails"
android:label="@string/title_activity_merchant_details" />
<activity
android:name=".Activities.GeneralSearchResult"
android:label="@string/title_activity_search_result"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.DisscountsFilter"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.DiscountsFilterResult"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.SaleDetails"
android:label="@string/title_activity_sale_details"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.MerchantsFilter"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.MerchantsFilterResult"
android:theme="@style/AppTheme.NoActionBar" />
<service android:name=".SendTokenIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".FireBaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity
android:name=".Activities.RegisterVerify"
android:label="@string/customer_register_verify_tittle" />
<activity
android:name=".Activities.CustomerHome"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.CustomerAddNumber"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.CustomerEditProfile"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.projects.epic.khosomaty.Activities.CustomerHome" />
</activity>
<activity android:name=".Activities.MerchantLogin" />
<activity android:name=".Activities.MerchantSignUp" />
<activity
android:name=".Activities.MerchantHome"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name=".Activities.MerchantHome" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Activities.MerchantAddDiscount" />
<activity android:name=".Activities.MerchantAddWallet" />
<activity
android:name=".Activities.MerchantRecievedRequests"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name=".Activities.MerchantRecievedRequests" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activities.WalletDetails"
android:label="@string/title_activity_wallet_details"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.RequestConfirmDetails"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.MerchantAddPurchase"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.CustomerTransaction"
android:parentActivityName=".Activities.CustomerHome"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name=".Activities.CustomerTransaction" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activities.MerchantRebatePoints"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activities.CustomerRebateConfirmation"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name=".Activities.CustomerRebateConfirmation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activities.CustomerWallet"
android:label="@string/title_activity_customer_wallet" />
<activity android:name=".Activities.CustomerFavoriteMerchants" />
<activity
android:name=".Activities.CustomerWalletTransactionDetails"
android:label="@string/title_activity_customer_wallet_transaction_details" />
<activity android:name=".Activities.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activities.CustomerWalletDetails"
android:label="@string/title_activity_customer_wallet_details" />
<activity android:name=".Activities.Intro"></activity>
</application>
</manifest>
有没有人知道为什么应用程序崩溃时,我生成apk ???
请注意我之前更改了包名称。
好吧,请确保不要使用build.gradle的applicationId字段中的新包名覆盖manifest.xml。
另外,如果我可以推荐一些东西:
public static synchronized MyApplication getInstance() {
return mInstance;
}
我认为这根本不是一个好主意。不要存储应用程序类的静态实例。我想建议使用activity.getApplication()任何传递作为参考!
嗨Badr请在下面的步骤和链接,然后UNCHECK即时运行,然后清洁,重建和运行项目后创建您的APK文件..
To disable Instant Run:
转到Android Studio
1-打开文件>设置或首选项对话框。
2-导航到构建,执行,部署>即时运行。
3-取消选中“启用即时运行”旁边的框。