可以设置debug / AndroidManifest.xml

时间:2019-05-21 11:58:35

标签: android gradle android-gradle

Android Studio 3.4

这是我的android应用程序结构:

enter image description here

我有2个 buildTypes

debug

release

这是我的src/debug/AndroidManifest.xml

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


    <application>
        <activity
            android:name="com.myapp.activity.CheckoutPaynetActivity_"
            android:screenOrientation="portrait"></activity>
    </application>
</manifest>

此清单文件仅包含增量。这是另一项活动。 releasedebug之间是不同的 版本

在我的app / buiil.gradle中,我将sourceSets更改为AndroidManifest:

  buildTypes {
        release {

        }
        debug {

            sourceSets {
                 debug {
                     manifest.srcFile 'debug/AndroidManifest.xml'
                }
            }
            configBuildType(delegate, DEBUG_INSTANCE_NAME, DEBUG_APP_NAME, null, DEBUG_APPLICATION_PROFILE_URL)
            ext.betaDistributionReleaseNotes = defaultConfig.versionName + " " + name
        }
    }

但是当我通过gradlew assembleDebug构建项目时, AndroidManifest 不包含其他活动= CheckoutPaynetActivity_

我通过Android Studio ->Build -> Analize APK...检查apk

def configBuildType(buildType, instanceName, appName, appIdSuffix, appProfileURL) {    
    buildType.resValue("string", "app_name", appName)
    buildType.applicationIdSuffix(appIdSuffix)
    buildType.buildConfigField("String", "INSTANCE_NAME", instanceName)
    buildType.buildConfigField("String", "APPLICATION_PROFILE_URL", appProfileURL)
}

1 个答案:

答案 0 :(得分:0)

在app / build.gradle中将清单位置添加为。

 sourceSets {
            main {
                //java.srcDirs = ['src/main/java']
                aidl.srcDirs = ['src/main/aidl']
                renderscript.srcDirs = ['src/main/rs']
                jni.srcDirs = []
                jniLibs.srcDirs = []
                res.srcDirs = ['src/main/res']
                assets.srcDirs = []
                manifest.srcFile 'AndroidManifest.xml'
            }
            test{
                java.srcDirs = ['test']
            }
            debug {
                // note that is merged with the main manifest, so we only need to add the debug only part
                manifest.srcFile 'AndroidManifest-debug.xml'
            }

        }