Android studio 未找到int io.netty.internal.tcnative.Library.aprMajorVersion()的实现
我一直在尝试实现谷歌的自然语言API。当我去验证我的凭证时,它与netty有问题。关于如何解决这个问题有什么线索吗?顺便说一句,我正在使用Java8。我在其他一些线程上看到,这是一个Java版本Android studio 未找到int io.netty.internal.tcnative.Library.aprMajorVersion()的实现,android-studio,google-api-client,Android Studio,Google Api Client,我一直在尝试实现谷歌的自然语言API。当我去验证我的凭证时,它与netty有问题。关于如何解决这个问题有什么线索吗?顺便说一句,我正在使用Java8。我在其他一些线程上看到,这是一个Java版本 String text = "My name is Teneala. I ran last week."; InputStream is = getResources().openRawResource(R.raw.credentials); try { Goog
String text = "My name is Teneala. I ran last week.";
InputStream is = getResources().openRawResource(R.raw.credentials);
try {
GoogleCredential credential = null;
credential = GoogleCredential.fromStream(is);
Collection<String> scopes = Collections.singleton("https://www.googleapis.com/auth/cloud-language");
if (credential.createScopedRequired()) {
credential = credential.createScoped(scopes);
}
// copy over key values, note the additional "s", set some expiry
// com.google.auth.oauth2.GoogleCredentials
GoogleCredentials sac = ServiceAccountCredentials.newBuilder()
.setPrivateKey(credential.getServiceAccountPrivateKey())
.setPrivateKeyId(credential.getServiceAccountPrivateKeyId())
.setClientEmail(credential.getServiceAccountId())
.setScopes(scopes)
.setAccessToken(new AccessToken(credential.getAccessToken(), null))
.build();
// Latest generation Google libs, GoogleCredentials extends Credentials
CredentialsProvider cp = FixedCredentialsProvider.create(sac);
LanguageServiceSettings settings = (LanguageServiceSettings) LanguageServiceSettings.newBuilder().setCredentialsProvider(cp).build();
LanguageServiceClient language = LanguageServiceClient.create(settings);
Document doc = Document.newBuilder()
.setContent(text)
.setType(Type.PLAIN_TEXT)
.build();
AnalyzeSyntaxRequest request = AnalyzeSyntaxRequest.newBuilder()
.setDocument(doc)
.setEncodingType(EncodingType.UTF16)
.build();
// analyze the syntax in the given text
AnalyzeSyntaxResponse response = language.analyzeSyntax(request);
// print the response
for (Token token : response.getTokensList()) {
System.out.printf("\tText: %s\n", token.getText().getContent());
System.out.printf("\tBeginOffset: %d\n", token.getText().getBeginOffset());
System.out.printf("Lemma: %s\n", token.getLemma());
System.out.printf("PartOfSpeechTag: %s\n", token.getPartOfSpeech().getTag());
System.out.printf("\tAspect: %s\n", token.getPartOfSpeech().getAspect());
System.out.printf("\tCase: %s\n", token.getPartOfSpeech().getCase());
System.out.printf("\tForm: %s\n", token.getPartOfSpeech().getForm());
System.out.printf("\tGender: %s\n", token.getPartOfSpeech().getGender());
System.out.printf("\tMood: %s\n", token.getPartOfSpeech().getMood());
System.out.printf("\tNumber: %s\n", token.getPartOfSpeech().getNumber());
System.out.printf("\tPerson: %s\n", token.getPartOfSpeech().getPerson());
System.out.printf("\tProper: %s\n", token.getPartOfSpeech().getProper());
System.out.printf("\tReciprocity: %s\n", token.getPartOfSpeech().getReciprocity());
System.out.printf("\tTense: %s\n", token.getPartOfSpeech().getTense());
System.out.printf("\tVoice: %s\n", token.getPartOfSpeech().getVoice());
System.out.println("DependencyEdge");
System.out.printf("\tHeadTokenIndex: %d\n", token.getDependencyEdge().getHeadTokenIndex());
System.out.printf("\tLabel: %s\n\n", token.getDependencyEdge().getLabel());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
```
没关系。我在这里找到了解决方案:。我不得不把它添加到应用程序构建gradle中。关于netty在Android设备上不受支持的事情
implementation 'io.grpc:grpc-okhttp:1.7.0'
implementation 'com.squareup.okhttp3:okhttp:3.0.1'
implementation 'io.grpc:grpc-okhttp:1.7.0'
implementation 'com.squareup.okhttp3:okhttp:3.0.1'