Missing Meta data in com.googlecode.libphonenumber:libphonenumber:8.8.2 while building signed APK
Asked Answered
N

1

6

I added com.googlecode.libphonenumber:libphonenumber:8.8.2 in my project. In debug mode its works normally.But in signed apk its generating the following exception when a library method is called.

Caused by: java.lang.IllegalStateException: missing metadata: /com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BD
    at com.google.i18n.phonenumbers.e.getMetadataFromSingleFileName(SourceFile:188)
    at com.google.i18n.phonenumbers.e.getMetadataFromMultiFilePrefix(SourceFile:116)
    at com.google.i18n.phonenumbers.g.getMetadataForRegion(SourceFile:64)
    at com.google.i18n.phonenumbers.PhoneNumberUtil.getMetadataForRegion(SourceFile:2211)
    at com.google.i18n.phonenumbers.PhoneNumberUtil.getMetadataForRegionOrCallingCode(SourceFile:1330)
    at com.google.i18n.phonenumbers.PhoneNumberUtil.parseHelper(SourceFile:3197)
    at com.google.i18n.phonenumbers.PhoneNumberUtil.parse(SourceFile:3025)
    at com.google.i18n.phonenumbers.PhoneNumberUtil.parse(SourceFile:3015)
    at com.revesoft.itelmobiledialer.util.aq.b(SourceFile:697)ode here
Neigh answered 10/7, 2018 at 10:8 Comment(2)
Did you ever find a solution to this one?Elisabeth
Hey Ashikee, any solutions?Jacobinism
G
1

Probably you have already fixed it, but it may help others. I had the same issue and I have fixed it as the library FAQs - How do I load libphonenumber resources in my Android app?

A possible problem can be that you are loading the metadata from the main thread. If this is not the case, then you can copy the data folder with the metadata in your app. Create an assets folder src/main/assets/data. In your application where you first want to read the data, create your own metadata loader that will read the metadata from its new destination. This is described in the link that I posted. The library FAQs suggest to delete the metadata files from the library in order not to duplicate files.

private static PhoneNumberUtil getPhoneNumberUtilInstance()
{
    if(mPhoneNumberUtil == null)
    {
        mPhoneNumberUtil = PhoneNumberUtil.createInstance(new MetadataLoader()
        {
            @Override
            public InputStream loadMetadata(String metadataFileName)
            {
                try
                {
                    String[] stringPieces = metadataFileName.split("/");

                    String metadataName = stringPieces[stringPieces.length - 1];

                    InputStream is = Factory.get().getApplicationContext().getAssets().open("data/" + metadataName);

                    return is;
                }
                catch (IOException e)
                {
                    // Handle somehow!
                    return null;
                }
            }
        });
    }

    return mPhoneNumberUtil;
}
Genera answered 6/4, 2019 at 21:2 Comment(1)
So, what was the solution? Not creating the instance in the main thread or creating a custom metadata loader ?Rohde

© 2022 - 2024 — McMap. All rights reserved.