fix: proteção contra crash por ausência da biblioteca Elgin e otimização de APK#3
Open
ShelmoLucas wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Descrição
Esta PR implementa proteções na inicialização do plugin nativo para garantir que o aplicativo não sofra um crash caso a biblioteca da Elgin (com.elgin.e1.Impressora) não esteja presente no projeto.
Anteriormente, se o arquivo .aar não fosse incluído nas dependências, o app encerrava inesperadamente logo na inicialização devido a um NoClassDefFoundError. Agora, o erro é capturado e tratado.
🚀 Motivação (Redução de APK e Flavors)
O principal motivo desta alteração é permitir que desenvolvedores utilizem Flavors para otimizar o tamanho do aplicativo:
🛠 Mudanças Realizadas
Proteção na Inicialização: Adicionado bloco try-catch (Throwable) ao instanciar a classe Printer no onAttachedToActivity, tratando falhas de carregamento de classe.
Feedback ao Flutter: Implementada verificação no onMethodCall. Se a impressora não estiver disponível, o plugin retorna o erro PRINTER_UNAVAILABLE em vez de causar um NullPointerException.
Refatoração do Handler: Corrigida a lógica do switch/case para evitar fall-through indesejado e separado o método getPlatformVersion das chamadas de hardware.
Ciclo de Vida: Adicionada verificação de nulidade ao desconectar o MethodChannel para evitar crashes em trocas rápidas de contexto.