Java Package is not public and cannot be accessed outside package

时间:2018-02-03 09:16:15

标签: java android react-native openid appauth

Hi I am not a pro java developer but I am trying to write an android native component for react native but I am facing following error log while writing it.

/Users/waqas.bhatti/Projects/es-tracker/mobile/tracker/custom_modules/custom-react-native-app-auth/android/src/main/java/com/reactlibrary/RNCustomAppAuthModule.java:27: error: AdditionalParamsProcessor is not public in net.openid.appauth; cannot be accessed from outside package
import static net.openid.appauth.AdditionalParamsProcessor.builtInParams;
                                ^
/Users/waqas.bhatti/Projects/es-tracker/mobile/tracker/custom_modules/custom-react-native-app-auth/android/src/main/java/com/reactlibrary/RNCustomAppAuthModule.java:27: error: static import only from classes and interfaces
import static net.openid.appauth.AdditionalParamsProcessor.builtInParams;
^
/Users/waqas.bhatti/Projects/es-tracker/mobile/tracker/custom_modules/custom-react-native-app-auth/android/src/main/java/com/reactlibrary/RNCustomAppAuthModule.java:28: error: AdditionalParamsProcessor is not public in net.openid.appauth; cannot be accessed from outside package
import static net.openid.appauth.AdditionalParamsProcessor.checkAdditionalParams;
                                ^
/Users/waqas.bhatti/Projects/es-tracker/mobile/tracker/custom_modules/custom-react-native-app-auth/android/src/main/java/com/reactlibrary/RNCustomAppAuthModule.java:28: error: static import only from classes and interfaces
import static net.openid.appauth.AdditionalParamsProcessor.checkAdditionalParams;
^
/Users/waqas.bhatti/Projects/es-tracker/mobile/tracker/custom_modules/custom-react-native-app-auth/android/src/main/java/com/reactlibrary/RNCustomAppAuthModule.java:106: error: cannot find symbol
                                .setCodeVerifier(CodeVerifierUtil.generateRandomCodeVerifier())
                                                 ^
  symbol: variable CodeVerifierUtil
5 errors

Any idea how can I import it? or is there any work around?

You many check this library from following URL: https://github.com/openid/AppAuth-Android/blob/master/library/java/net/openid/appauth/AuthorizationServiceConfiguration.java#L102

1 个答案:

答案 0 :(得分:1)

One ugly workaround for invoking package protected methods is to place a own Class in that package with an public method that forwards the method invocation.

For example:

public class net.openid.appauth.PublicWorkarround {
    public static Set<String> buildInParams(Set<String> params) {
        return net.openid.appauth.AdditionalParamsProcessor.builtInParams(params);
    }
}