Olá a todos, espero que estejam bem.
Vamos lá, trabalhando com implementação de maquinas POS ( Aquelas que tem a própria loja onde posta o aplicativo e seus clientes podem baixar para fazer venda direto na maquininha ), tive um grande desafio, uma das lojas não aceita de maneira alguma que um package e suas permissões estejam presente no build do aplicativo, exemplo:
Loja A - utiliza o package AAA.jar
Loja B - utiliza o package BBB.jar
Quando eu crio o build do meu aplicativo, ela puxa tudo sem excluir nada, porem no exemplo acima a loja A até aceita qualquer package, porem a loja B não aceita que tenham outros.
Se pensar apenas que você trabalhe com 2 lojas, é simples, vá até a pasta android e duplique ela e renomeie para quando for buildar A e quando for buildar B renomeie de novo alterando o mainActivity para cada uma.
Imagine você tendo que fazer 15 lojas... com isso em mente pensei em fazer o flavor, que já estava sendo utilizado mas não encontrei maneiras de como não importar as coisas que eu não preciso, estudando os packages e lendo pela internet encontrei uma solução que funcionou até o momento, veja :
A pasta android é composta por:
Em build.gradle fica a configuração de como o nosso aplicativo tem que ser buildado com relação a imports, packages e tudo mais e é nesse arquivo que será criado o flavor. Mas antes temos que fazer mais alterações
Dentro da pasta app/src/main fica seu AndroidManifest.xml que é o arquivo que vai setar sua MainActivity :
A MainActivity é a classe principal de uma aplicação Android. Ela serve como ponto de entrada para a interação do usuário com a interface do aplicativo. A MainActivity gerencia a exibição de layouts, a manipulação de eventos e a comunicação com outros componentes do sistema operacional. É nela que ocorrem as principais interações e a lógica de inicialização da aplicação.(Informação tirada do ChatGPT)
Então ela ira iniciar todas as suas classes no Android.
Meu primeiro passou foi criar uma pasta dentro de app/src e colocar o nome da loja que vou buildar.
Após isso, copiei o mainActivity que está dentro da main e coloquei o nome mainActivityLojaB, lembre-se de mudar o nome para da classe tambem para não dar duplicidade.
Agora vou até app/src/main e copio o AndroidManifest.xml e jogo para app/src/loja_b
Dentro do AndroidManifest.xml eu altero o apontamento da .Mainactivity para .MainActivityLojaB, fazendo com que na hora da inicialização ela utilize a configuração da mainActivity desejada.
Por fim mas não menos importante temos que criar o flavor e definir qual pasta ele deve inicializar e qual excluir.
dentro de build.gradle, crie assim
productFlavors{
E no momento de buildar eu chamo o flavor - productFlavors
Dessa maneira consegui resolver a questão onde eu não conseguia compilar um aplicativo sem chamar libs que são indesejadas.
Espero conseguir ajudar alguem, se de 10 pessoas que buscarem no google e cairem nesse post, 1 eu conseguir ajudar, já me sinto realizado.
Pode me chamar e mandar mensagem que ajudo no que eu puder. gitHub - https://github.com/Guimarte
Linkedin - https://www.linkedin.com/in/guilherme-martins-0397ab17b/
Hello everyone, I hope you're well. So, working on the implementation of POS machines (those that have their own store where they post the application and their customers can download it to make direct sales on the device), I had a big challenge. One of the stores does not accept, in any way, that a package and its permissions are present in the application build. For example:
Store A - uses the AAA.jar package
Store B - uses the BBB.jar package
When I create the build of my application, it pulls everything without excluding anything. However, in the example above, Store A accepts any package, but Store B doesn't accept any others.
If you only consider working with 2 stores, it's simple. Go to the Android folder, duplicate it, and rename it for when building A and when building B, rename it again, changing the MainActivity for each one.
Now, imagine having to do this for 15 stores... With that in mind, I thought about using flavors, which was already being used, but I couldn't find ways to not import the things I don't need. Studying the packages and researching online, I found a solution that worked so far, let's see:
The Android folder is composed of:
The build.gradle file contains the configuration for how our application should be built regarding imports, packages, and more. It is in this file that the flavor will be created. But before that, we have to make more changes. Inside the app/src/main folder, there's your AndroidManifest.xml file that sets your MainActivity:
The MainActivity is the main class of an Android application. It serves as the entry point for user interaction with the application's interface. The MainActivity manages the display of layouts, event handling, and communication with other components of the operating system. It is where the main interactions and application initialization logic occur. (Information taken from ChatGPT)
So, it will start all your classes in Android.
My first step was to create a folder inside app/src and name it after the store I'm building for. After that, I copied the MainActivity from the main folder and named it MainActivityStoreB, remembering to change the class name as well to avoid duplication.
Now, I go to app/src/main, copy the AndroidManifest.xml file, and paste it into app/src/store_b.
Inside the AndroidManifest.xml file, I change the reference from .MainActivity to .MainActivityStoreB, so that during initialization, it uses the desired MainActivity configuration.
Last but not least, we have to create the flavor and define which folder it should initialize and which one to exclude.
Inside build.gradle, create it like this:
And when building, I call the flavor - productFlavors.
This way, I was able to solve the issue where I couldn't compile an application without including unwanted libs. I hope I can help someone. If out of 10 people who search on Google and come across this post, I can help 1, I already feel accomplished. Feel free to call and send me a message, and I'll help as much as I can.
gitHub - https://github.com/Guimarte
Linkedin - https://www.linkedin.com/in/guilherme-martins-0397ab17b/
Top comments (0)