gpt4 book ai didi

android - 如何更改应用程序 ID 但保持相同的资源 ID?

转载 作者:行者123 更新时间:2023-11-29 15:47:30 25 4
gpt4 key购买 nike

在 Android 项目中,资源 ID 完全由应用程序 ID 标识。例如,如果我的 appid 是 com.mycompany.myapp,则资源 id 将是 com.mycompany.myapp.R.blah。

在我的例子中,我需要创建两个版本的应用程序 - 测试版和发布版。这两个版本可以安装在同一台设备上。仅当 appid 不同时才会发生这种情况。我的策略是,在夜间构建期间,我将以编程方式修改 list 文件并将 appid 更改为 com.mycompany.myappbeta。但是,如果我这样做,我将需要接触大量使用资源 ID 的源文件。

我想知道 list 文件中是否有一些标记,我可以在其中明确说明如何限定资源 ID?问候。

编辑

原来app id和package id确实是两个不同的概念。我想更改 app-id 但不是 package-id。但是,这似乎在 Eclipse 下是不可能的。正如其他帖子所指出的,Gradle 构建可以处理更改应用程序 ID 但保留包 ID。我现在要转到 Android Studio。

最佳答案

the resource ids are fully identified by the application id

从技术上讲,它们由包名称标识,来自根 list 中的 package 属性。

My strategy is, during the nightly build, I will programmatically modify the manifest file and change the appid to com.mycompany.myappbeta. However, if I do this, I would need to touch a number of source files that are using the resource ids.

这就是为什么您的夜间构建应该使用 Gradle 和 Gradle for Android 插件。然后,您跳过所有描述的内容,而是使用构建类型。预定义了两种构建类型(debugrelease),如果您想发明另一种(例如,beta),您可以.然后,在 build.gradle 文件的构建类型配置中,您使用 applicationIdSuffix 为非 release 构建一个不同的后缀。出于唯一安装的目的,它将添加到应用程序 ID,但您的包名称不受影响,因此您的资源不受影响。

例如:

android {
compileSdkVersion 19
buildToolsVersion "21.1.2"

defaultConfig {
versionCode 2
versionName "1.1"
minSdkVersion 14
targetSdkVersion 18
}

signingConfigs {
release {
storeFile file('HelloConfig.keystore')
keyAlias 'HelloConfig'
storePassword 'laser.yams.heady.testy'
keyPassword 'fw.stabs.steady.wool'
}
}

buildTypes {
debug {
applicationIdSuffix ".d"
}

release {
signingConfig signingConfigs.release
}

beta.initWith(buildTypes.release)

beta {
applicationIdSuffix ".beta"
debuggable true
}
}
}

我在这里:

  • debug 构建类型提供 .d

    的应用程序 ID 后缀
  • 从应用程序 ID 后缀的角度出发,保留 release 构建类型

  • 创建一个新的 beta 构建类型,从 release 构建类型克隆,我给它一个 .beta 应用程序 ID后缀并将其标记为可调试

关于android - 如何更改应用程序 ID 但保持相同的资源 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32237975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com