重命名包后,我的项目在 android 中构建时显示错误

After renaming package my project showing error while building in android

重命名包后,我的项目在 android 中构建时显示错误。

我用这个:Android Studio Rename Package 重命名我的项目,然后它开始出现这些错误:

Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

然后我用了https://developer.android.com/tools/building/multidex.html 用于解决第一个错误,但这也没有用。

所以我重新启动了 Android Studio,然后再次尝试构建,但出现了同样的错误。

然后我尝试撤消回到旧的包名称,但没有任何好事发生..... 请帮助!...

提前致谢......

能否请您在 build.gradle

中添加以下代码
android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

并在您的 ApplicationClass 中添加以下代码。

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

我认为有一种单独的方法可以提高 dexing 操作的堆限制。将此添加到 build.gradle 文件中的 android 闭包:

dexOptions {
    javaMaxHeapSize "4g"
}

首先在代码下方添加build.gradle

dependencies {//just add below one in dependency
compile 'com.android.support:multidex:1.0.0' ....//no change your old jar file.....}

然后

android {
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
    applicationId "your pkg name"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 6
    versionName "v2.5.2.2"
    multiDexEnabled true // just add it
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}
dexOptions { //add it
    javaMaxHeapSize "4g"
}}

在清单文件中

<application
android:name=".Education_multidex" //add what ur create java file
android:allowBackup="true"
android:icon="@drawable/rvms_education_luncher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"> ....</application>

然后创建并添加一个 java 文件,例如 Education_multidex.java

public class Education_multidex extends MultiDexApplication {/* @Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}*/}

最终构建您的应用,然后在 java 文件

中添加导入一些库