Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WalletUtils.generateBip39Wallet fails when library is used as .jar in a project #343

Closed
Zurvarian opened this issue Jan 30, 2018 · 4 comments

Comments

@Zurvarian
Copy link

I've testing the recently new added functionality to allow creation of Wallets from BIP39 mnemonics, and during testing I've found that there is an issue with loading the list of words from the file.

Problem is that current piece of code

private static List<String> populateWordList() {
        URL url = Thread.currentThread().getContextClassLoader()
                .getResource("en-mnemonic-word-list.txt");
        try {
            return Files.readAllLines(Paths.get(url.toURI()));
        } catch (Exception e) {
            return Collections.emptyList();
        }
    }

Is trying to load the file as if it is a system file, which if contained inside a .jar won't work.

I've created an alternative snippet of code, I'm using Java 8 so not sure if 100% compatible with Android, that works:

InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("en-mnemonic-word-list.txt");
        try (Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name())) {

            List<String> lines = new ArrayList<String>();
            while (scanner.hasNext()) {
                lines.add(scanner.nextLine());
            }

            System.out.println(lines);
        }
@conor10
Copy link
Contributor

conor10 commented Mar 2, 2018

New release for Java and Android has gone out with this support.

@conor10 conor10 closed this as completed Mar 2, 2018
@ghost
Copy link

ghost commented Jul 19, 2018

@conor10 i have used implementation 'org.web3j:core:3.3.1-android' still i m facing issue .MnemonicUtils.class is not updated in jar.kindly help

@vasa-develop
Copy link

vasa-develop commented Nov 1, 2018

@conor10 What is the best way to get around this populateWordList() issue?
Creating .jar files didn't work for me as it has too many dependencies, so it doesn't seem a feasible way to fix it like this. Also, there seems to be no way to handle this error from my side.

@Zurvarian did you solved this problem?

@Zurvarian
Copy link
Author

I was able to avoid the issue by copying the en-mnemonic-word-list.txt file under the root /resources directory of my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants