Android - 白标应用程序

发布于 2024-10-08 18:13:29 字数 335 浏览 3 评论 0原文

注意:这是一个老问题,相应的旧的赞成答案可能不相关 - 请参阅有关构建变体(又名应用程序风格)的新答案。< /p>

我有一个问题关于发布到市场。

X 公司为 A 公司和 X 公司提供类似的服务。 B,以及 A 和 A 都B 想要市场上有一个应用程序。 X 公司只想编写一个应用程序,并在编译时使用适当的徽标、配置设置、语言字符串来区分它们。但是,在发布时,应用程序具有相同的应用程序包名称(使用共享代码库)。该应用程序将得到维护

,因此,鉴于我想保留单个代码库,这里的最佳实践是什么?

NOTE: This is an old question, and the correspondingly old upvoted answer may not be relevant - see the newer answers about Build Variants (a.k.a. App Flavors).

I have a question about publishing to the marketplace.

Company, X, provides similar services for companies A & B, and both A & B want an app in the market place. Company X wants to write just one app and differentiate between them using the appropriate logo's, configuration settings, language strings at compile time. However, when it comes to publishing, the apps have the same app package name (using shared code base). The app will be maintained and

So, given that I want to keep a single code base, what is the best practice here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

聚集的泪 2024-10-15 18:13:29

据我所知,市场上不能有两个具有相同包名称的应用程序。为了避免复制粘贴共享代码、布局、可绘制对象等,我建议将这些资源放入库项目中,然后从您提到的应用程序 A 和 B 引用该项目,在这些应用程序中只需覆盖您想要更改的值。

有关库项目的更多信息,请参阅官方文档

As far as I know you can't have two apps on Market with the same package name. To avoid copy-paste of shared code, layouts, drawables etc I would recommend to put the these resources into a library project and then reference this project from app A and B that you mention and in these apps just override the values you want to change.

More about library projects in the official documentation.

冷夜 2024-10-15 18:13:29

请参阅这篇博文,blog.javia.org/android-package-name/

[编辑] 为了避免此链接失效时信息丢失:这是一篇关于应用程序包定义和 java 包定义之间的差异的帖子。可以在不触及源代码的 java 包的情况下更改应用程序包(在清单内)。[/编辑]

See this blog post, blog.javia.org/android-package-name/.

[edit] To avoid a loss of information if this link dies: Its a post about the difference of the application package definition and the java package definition. Its possible to change the application package (inside the manifest) without touching the java package of the sources.[/edit]

素年丶 2024-10-15 18:13:29

这是一个很老的问题。但是现在我认为最好的方法是使用 产品风味< /a> 适用于使用新 gradle 构建系统的 Android。

  • 对于每种风格,您都可以定义applicationIdpackageNameapplicationId 之间存在差异。 ApplicationId 唯一标识您在设备上和 Google Play 商店中的应用程序。后者用于代码命名空间。您可以在这里阅读更多信息: https://developer.android.com/studio/ build/application-id.html
  • 对于每种风格,您可以使用该风格的特定文件夹拥有不同的绘图、字符串和其他 xml 文件。您只需将这些资产放入新文件中,该文件与 main 文件夹中的资产不同。然后,您可以在 build.gradle 中为每种风格定义 buildConfigField ,它可以从 Java 文件中访问,作为每个白标签的配置。
  • 您还可以从那里为每种风格定义 resValue
  • 您还可以使用 清单占位符

This is a pretty old question. However now I think the best approach will be to use Product Flavours for Android using the new gradle build system.

  • For each flavour you can define applicationId. There is a difference between packageName and applicationId. ApplicationId uniquely identifies your app on the device and in Google Play Store. The latter is for code namespace. You can read more here: https://developer.android.com/studio/build/application-id.html
  • For each flavour, you can have a different drawables, strings, other xml file using specific folder for the flavour. You only need to put those assets into the new files, which differ from assets in the main folder. Then there is buildConfigField you can define for each flavour in build.gradle which can be accessed from Java files as your configs for each whitelabel.
  • Also you can define resValue for each flavour from there.
  • You can also make your AndroidManifest.xml configurable for keys etc using manifestPlaceholders.
酒解孤独 2024-10-15 18:13:29

约翰的回答是正确的。在我的公司中,我们刚刚构建了一个小脚本,它不仅通过应用新资源,而且还创建自定义包名称并修补适当的 XML 文件,从一个“基础”应用程序创建应用程序“品牌”。

johan's answer is correct. In my company, we just built a small script that creates 'brands' of application from one 'base' application, by not only applying new resources, but also creating a custom package name and patching the appropriate XML files.

空城仅有旧梦在 2024-10-15 18:13:29

我同意Reflog所说的,我的公司使用了ant脚本来更改每个品牌的包名称,并且还根据需要更换资源。我在编写基本应用程序时考虑到了默认行为,并为每个附加品牌创建了仅包含与基本不同的文件的文件夹,就像具有不同 dpi 大小的多个可绘制文件夹(“drawable”、“drawable-hdpi”)一样。 ..)。其他更改包括修改每个品牌的字符串文件以获取适当的颜色和法律文本。

通过以本地化风格命名它们(例如“drawable-en-rAA-hdpi”、“layout-en-rBB”...),我可以通过打开“自定义区域设置”应用程序在多个模拟器中快速测试这一点在每个模拟器中,根据需要将区域设置设置为“en_AA”、“en_BB”。通过保存基本 AVD 的多个副本,我能够保存这些设置,因此我不必在模拟器内切换来测试所有最终品牌。

这种方法的一个警告是,该应用程序的模拟版本将包含 .apk 中的所有文件,而 ant 脚本会删除重复项。此外,虽然此“完整”.apk 将安装在设备上,但它只会显示默认行为,除非您可以在设备上设置区域设置以匹配品牌区域设置。 (自定义区域设置未安装在我的任何物理设备上。)如果您有意使用现有的命名区域设置(en_AU、en_CA、en_GB),此方法效果很好,但对于自定义名称(en_B1、en_XX)可能会出现问题。

I agree with what Reflog said, my company used an ant script to change the package name for each brand, and also to replace resources as needed. I wrote the base app with default behavior in mind, and created folders for each additional brand containing only those files that were different from the base, just like the multiple drawable folders with different dpi sizes ("drawable", "drawable-hdpi"...). Other changes included modifying the strings files for each brand for appropriate colors and legal text.

By naming them in the localization style (for instance "drawable-en-rAA-hdpi", "layout-en-rBB"...), I was able to test this quickly in multiple emulators by opening the "Custom Locale" app in each emulator, and setting the locale to "en_AA", "en_BB" as needed. By saving multiple copies of the base AVD, I was able to save those settings so I didn't have to switch within the emulator to test all the final brands.

One caveat to this approach is this emulated version of the app will include all the files in the .apk, while the ant script strips out the duplicates. Also, while this "full" .apk will install on devices, it will only show the default behavior unless you can set the locale on the device to match the brand locale. (Custom Locale was not installed on any of my physical devices.) This works well if you intentionally use existing named locales (en_AU, en_CA, en_GB), but can be problematic for custom names (en_B1, en_XX).

自找没趣 2024-10-15 18:13:29

我知道我来晚了一点,但您可以通过以下方式执行此操作:

1)通过添加行 manifestmerger.enabled=true 更改您的project.properties

2)更改您的包名称
显现。

3)更新/更改您的资源、绘图、字符串等。

4) 将您的主项目标记为库,并在白标签项目中设置它的依赖关系。瞧,白标!

I know I'm a little late to the party but you can do this by:

1) Change your project.properties by adding the line manifestmerger.enabled=true

2) Change your package name in the
manifest.

3) Update/change your resources, drawables, strings, whatever.

4) Mark your master project as a library and set the dependency for it in your white-label project. Voila, white-label!

清晰传感 2024-10-15 18:13:29

您需要的是构建变体(又名应用程序风味)。

您可以在这里阅读 https://developer.android.com/studio /build/build-variants.html

简而言之,这允许您拥有应用程序的不同变体,这些变体共享部分代码和资源,但也可以有自己的替代品。您可以为每个变体指定不同的包名称/ID,以及其他内容(例如徽标、颜色、启动屏幕甚至 Java 代码)。

defaultConfig {
    applicationId "com.example.example"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0.0"
}

productFlavors {
    variantone {
            applicationId 'com.company1.example'
    }
    varianttwo {
            applicationId 'com.company2.example'
    }
}

您可以使用变体的名称创建资源文件夹,您可以在其中放置替代资源或源代码。例如,src/variantone/res

在 Android Studio 中的构建变体之间切换不会导致文件更改(您只需选择“输出”)。您可以同时为您想要的所有变体构建 APK。使用构建/生成签名 APK 中的向导。

PS 以下是如何为调试版本使用不同的包名称:

buildTypes {
    release {
    }
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '.debug'
    }
}

What you need is Build Variants (a.k.a. App Flavors).

You can read up on it here https://developer.android.com/studio/build/build-variants.html

In short, this allows you to have different variants of your app that share part of the code and resources, but can have their own replacements as well. You can specify different package name/id for each variant, among other things (like logo, colors, splash screen and even java code).

defaultConfig {
    applicationId "com.example.example"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0.0"
}

productFlavors {
    variantone {
            applicationId 'com.company1.example'
    }
    varianttwo {
            applicationId 'com.company2.example'
    }
}

You can create resource folders with the name of the variants where you can place your alternative resources or source code. For instance, src/variantone/res

Switching between build variants in Android Studio does not result in file changes (you just choose the "output"). You can build APKs for all the variants you want at the same time. Use the wizard in Build/Generate signed APK.

P.S. Here's how you can have a different package name for Debug builds:

buildTypes {
    release {
    }
    debug {
        applicationIdSuffix '.debug'
        versionNameSuffix '.debug'
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文