简体   繁体   English

如何在Android Studio中为不同的Gradle风格创建包

[英]How to create packages in Android Studio for different gradle flavors

I am new to android programming. 我是android编程的新手。 I just released my app. 我刚刚发布了我的应用。 All works well and everything. 一切正常,一切正常。 However I was thinking of making a new flavor (free) version of the app by using the flavor feature of gradle . 但是,我正在考虑通过使用gradle风味功能制作该应用的新风味(免费) 版本

Now all the tutorials and example of flavors that i see tell about storing exclusive classes of different flavors separate, for instance 现在,我看到的所有风味的教程和示例都讲述了如何将不同风味的互斥类分别存储,例如

com.example.myapp.free com.example.myapp.free

com.example.myapp.paid com.example.myapp.paid

and keep the common files in main. 并将公用文件保存在main中。 Now my issue is, since i have already released the app, I cannot change the package name of my app to the .paid name as mentioned above. 现在我的问题是,由于我已经发布了该应用程序,因此无法如上所述将应用程序的程序包名称更改为.paid名称。 However my free version will implement the same class with different logic. 但是我的免费版本将使用不同的逻辑实现相同的类。 If I do this, I get the duplicate class:com ... error 如果这样做,我得到重复的class:com ...错误

How do i get around this situation? 我如何解决这种情况?

Finally got the solution: 终于得到了解决方案:

defined gradle config like this: 定义gradle配置是这样的:

    productFlavors {
    free {
        applicationId "com.blah.blah.free"
    }
    paid {
        applicationId "com.blah.blah"
    }

This allowed me to keep the release package same, and at the same time, I added learned the hard way to design and modularize app properly. 这使我可以保持发布包不变,同时,我还学会了正确设计和模块化应用程序的艰难方法。 I had make copies of my activity classes in both flavors and delete from main. 我已经制作了两种风格的活动类副本,并从main中删除了。 Resource overriding automatically handles everything except the classes. 资源覆盖会自动处理除类之外的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM