Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 251
Ashikee AbHi Avatar asked Nov 07 '22 04:11

Ashikee AbHi


1 Answers

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;
}
like image 169
Georgi Zhelev Avatar answered Nov 29 '22 22:11

Georgi Zhelev