Error Building Android App - android

I am getting a weird error when I am trying to build a app. I don't think it's related to my code and need some help in resolving it. When I press run, the logcat giving me this error:
Could not upload stats checkin to cyanogen server
javax.net.ssl.SSLHandshakeException: Connection closed by peer
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)
at com.android.okhttp.Connection.upgradeToTls(Connection.java:201)
at com.android.okhttp.Connection.connect(Connection.java:155)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:217)
at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:25)
at com.android.settings.cmstats.StatsUploadJobService.uploadToCyanogen(StatsUploadJobService.java:223)
at com.android.settings.cmstats.StatsUploadJobService.access$000(StatsUploadJobService.java:43)
at com.android.settings.cmstats.StatsUploadJobService$StatsUploadTask.doInBackground(StatsUploadJobService.java:121)
at com.android.settings.cmstats.StatsUploadJobService$StatsUploadTask.doInBackground(StatsUploadJobService.java:93)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
The gradle console then says:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:484)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:261)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:473)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:161)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
I am wondering if it to do with my phone's hardware or the cyanogenmod software running on it which causes the error.
Thank you for the help.

You hit the DEX 64k method limit.
There are few solutions which will help you to resolve this problem:
remove unused gradle dependencies
replace libaries with huge amount of methods with smaller ones, e.g.:
compile 'com.google.android.gms:play-services-analytics:8.4.0'
->
compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
...
remove unused code by configuring the ProGuard
enable Multidex:
build.gradle
android {
...
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Reference:
Building Apps with Over 65K Methods.

This line com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 states that you are over the 64k method limit the Compiler has for every .dex file. Read up on it. Solutions include using Multidex or more solutions here https://www.contentful.com/blog/2014/10/30/android-and-the-dex-64k-methods-limit/. This maybe a duplicate of other issues. Look at
How to solve the issue with Dalvik compiler limitation on 64K methods?

Related

Running google cloud speech api on Android 4.2

I have a problem running io.grpc:grpc-okhttp on Android 4.2 devices.
I have implemented SpeechClient with Credentials, for running Google cloud speech to text.
On Android 7.1 device I don't have a problem. The problems happen on Android 4.2
So in my starting gradle I had
implementation 'io.grpc:grpc-okhttp:1.35.0'
implementation 'io.grpc:grpc-android:1.35.0'
implementation 'com.google.cloud:google-cloud-speech:1.24.0'
Problems.
First problem was with TLS security for SSL (which is too old on Android 4.2). For this, I added dependency
implementation 'org.conscrypt:conscrypt-android:2.5.1'
and implemented in my DialogFragment (which is running the code)
Security.insertProviderAt(Conscrypt.newProvider(), 1)
After I implemented this, I am getting
Duplicate class org.conscrypt.AbstractConscryptEngine found in modules jetified-conscrypt-android-2.5.1-runtime (org.conscrypt:conscrypt-android:2.5.1) and jetified-conscrypt-openjdk-uber-2.2.1 (org.conscrypt:conscrypt-openjdk-uber:2.2.1)
issues (alot of duplicated classes)
So for fixing this, I added
configurations {
all {
exclude group: "org.conscrypt", module: "conscrypt-openjdk-uber"
}
}
Now I get this error, because com.google.api.client is using Standard.UTF-8 and my device is on Android 17.
com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:73)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:72)
at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:60)
at com.google.api.gax.grpc.ExceptionResponseObserver.onErrorImpl(ExceptionResponseObserver.java:82)
at com.google.api.gax.rpc.StateCheckingResponseObserver.onError(StateCheckingResponseObserver.java:86)
at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)
at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: io.grpc.StatusRuntimeException: UNAUTHENTICATED: Failed computing credential metadata
at io.grpc.Status.asRuntimeException(Status.java:533)
at com.google.api.gax.grpc.GrpcDirectStreamController$ResponseObserverAdapter.onClose(GrpcDirectStreamController.java:149) 
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426) 
at io.grpc.internal.ClientCallImpl.access$500(ClientCallImpl.java:66) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:689) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$900(ClientCallImpl.java:577) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:751) 
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:740) 
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) 
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
at java.lang.Thread.run(Thread.java:856) 
Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
at com.google.api.client.util.StringUtils.getBytesUtf8(StringUtils.java:51)
at com.google.api.client.json.webtoken.JsonWebSignature.signUsingRsaSha256(JsonWebSignature.java:571)
at com.google.auth.oauth2.JwtCredentials.refresh(JwtCredentials.java:125)
at com.google.auth.oauth2.JwtCredentials.getRequestMetadata(JwtCredentials.java:163)
at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:365)
at com.google.auth.Credentials.blockingGetToCallback(Credentials.java:112)
at com.google.auth.oauth2.ServiceAccountJwtAccessCredentials.getRequestMetadata(ServiceAccountJwtAccessCredentials.java:341)
at io.grpc.auth.GoogleAuthLibraryCallCredentials.applyRequestMetadata(GoogleAuthLibraryCallCredentials.java:110)
at io.grpc.CallCredentials2.applyRequestMetadata(CallCredentials2.java:58)
at io.grpc.internal.CallCredentialsApplyingTransportFactory$CallCredentialsApplyingTransport.newStream(CallCredentialsApplyingTransportFactory.java:108)
at io.grpc.internal.ForwardingConnectionClientTransport.newStream(ForwardingConnectionClientTransport.java:49)
at io.grpc.internal.InternalSubchannel$CallTracingTransport.newStream(InternalSubchannel.java:671)
at io.grpc.internal.DelayedClientTransport$PendingStream.createRealStream(DelayedClientTransport.java:353)
at io.grpc.internal.DelayedClientTransport$PendingStream.access$300(DelayedClientTransport.java:341)
Question:
How to resolve this issue and run Speech with "ApiStreamObserver?
I tried reverting back "io.grpc:grpc-" libraries to version 1.0 or something, but then I have other problems...
I have resolved this issue and commited example project on Github
https://github.com/DjToMeK27/CloudGoogleSpeechToText/tree/main
What I did in this project
Downloaded https://github.com/GoogleCloudPlatform/android-docs-samples/blob/master/README.md
Changed classes in project SpeechRecognitionClient in android-docs-samples-master\speech
Changed AudioRecord in AudoEmitter.kt to support API 16
Imported org.conscrypt:conscrypt-android:2.5.1 library
Had to exclude group org.conscrypt from google-cloud-speech (in build.gradle)
Added init { Security.insertProviderAt(Conscrypt.newProvider(), 1) } For Android 4.1 to run proper TLS for GRC to work
I downloaded https://github.com/googleapis project
Changed all StandardCharsets found in google-http-client to Charset.forName())
And also changed some tests to work
https://imgur.com/a/iU7yjCZ (files changes)
I have build this project and added .jar files, which I included here
And now it works!

Problems getting started with Chirp SDKs for Android

I have downloaded SDK for Android from
https://developers.chirp.io/downloads
After that I added *.aar library as was explain here:
https://developer.android.com/studio/projects/android-library.html#AddDependency
Hurrah. I can build the project.
Now I want to install the test App on the phone. But the application crashes like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 12979
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:2)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
As I understand it, a problem arose with dependencies when packaging * aar
So I added in build.gradle (marked as Module) dependency for kotlin like:
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.2.61'
After that my ERROR has changed.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 13395
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/MediaType;
at io.chirp.b.a.<init>(Unknown Source:24)
at io.chirp.chirpsdk.a.<init>(Unknown Source:36)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:20)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
I have wrong paths to io.chirp internal libraries.
What should I do to resolve dependency related errors?
You have to import the okhttp 3.12.x dependency required by the ChirpSDK.
However, you don't need to explicitly import the dependency if you are using the SDK from the maven repository as this will be already included:
implementation 'io.chirp:chirpsdk:3.10.0'
and add the repository in your parent maven file:
repositories {
maven {
url "https://maven.chirp.io/release"
}
}
Thanks Dinu for your answer!
Maven repository doesn't work in my case (proxy issues or something else but this is the topic of another discussion).
The problem with using offline ChirpSDK was solved by adding two dependencies:
implementation 'com.squareup.okhttp3:okhttp:3.12.6'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'

transformClassesWithDexBuilderForDebugAndroidTest error

I'm getting this weird error, and can't seem to understand what's the problem:
com.android.build.api.transform.TransformException:
com.android.builder.dexing.DexArchiveBuilderException:
com.android.builder.dexing.DexArchiveBuilderException: Failed to
process
.../Android/sdk/extras/android/m2repository/com/android/support/support-v4/19.1.0/support-v4-19.1.0.jar
caused by, caused by, caused by ...
Caused by: com.android.tools.r8.utils.AbortException: Error: Type
android.support.v4.app.FragmentContainer is referenced as an interface
from android.support.v4.app.Fragment$1.
at com.android.tools.r8.utils.Reporter.failIfPendingErrors(Reporter.java:89)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:60)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:64)
... 11 more
Note that I don't even use the v4-19.1.0, I only call:
implementation 'com.android.support:appcompat-v7:28.0.0'
In the end it seems the problem was that I was missing some dependencies:
androidTestImplementation "com.squareup:fest-android:1.0.8"
androidTestImplementation "org.mockito:mockito-android:2.18.3"
androidTestImplementation "com.android.support:support-annotations:28.0.0"
Seemed to solve it.

java.lang.VerifyError: com/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential$RequestHandler

My android app well work last month. but just upgrade
compile 'com.google.android.gms:play-services-drive:8.4.0'
->
compile 'com.google.android.gms:play-services-drive:9.0.2'
after
java.lang.VerifyError: com/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential$RequestHandler
at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.initialize(GoogleAccountCredential.java:144)
at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:93)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:300)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.jhjg.skhu_drive.Controller.GoogleFileHelper$1.run(GoogleFileHelper.java:79)
at java.lang.Thread.run(Thread.java:841)
error point is File file = service.files().insert(body).execute();
What should i do?
I had a similar problem with the calendar api. After some hours I added additionally the dependency:
compile 'com.google.android.gms:play-services-auth:9.2.1'
Then, the app worked again.

Hitting 65k Dex method limit but dex-method-count tools says there is much fewer

We've struggled with the 65k method limit for a long time and have done most of the optimizations already. Now I'm trying to add the Jacoco plugin and I'm getting the dex limit error again:
Error:Execution failed for task ‘:MyProject:dexExternalBetaDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/orrieshannon/Code/sdk/sdk/build-tools/21.1.1/dx --dex --no-optimize --output /Me/MyProject/build/intermediates/dex/externalBeta/debug --input-list=/Me/MyProject/build/intermediates/tmp/dex/externalBeta/debug/inputList.txt
Error Code:
2
Output:
objc[80218]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: Cannot merge new index 66105 into a non-jumbo instruction!
at com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:109)
at com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:26)
at com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:72)
at com.android.dx.io.CodeReader.callVisit(CodeReader.java:114)
at com.android.dx.io.CodeReader.visitAll(CodeReader.java:89)
at com.android.dx.merge.InstructionTransformer.transform(InstructionTransformer.java:49)
at com.android.dx.merge.DexMerger.transformCode(DexMerger.java:842)
at com.android.dx.merge.DexMerger.transformMethods(DexMerger.java:813)
at com.android.dx.merge.DexMerger.transformClassData(DexMerger.java:786)
at com.android.dx.merge.DexMerger.transformClassDef(DexMerger.java:682)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:542)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
However when I run the dex-method-count tool (found here https://github.com/mihaip/dex-method-counts) it says we are only at 56k methods.
Read in 56024 method IDs.
<root>: 56024
: 4
android: 10877
accessibilityservice: 6
...
The Jacoco library is only 1309 methods (counted using the same dex-method-count tool) so we should be well under 65k limit.
Any ideas? Anyone else noticed the dex-method-count tool underreporting the number of methods?
Thanks to #JesusFreke for pointing it out, it turns out the limit was in the number of strings being too large, not the number of methods. To increase the number of strings to 2^32 (instead of default 2^16) enable jumboMode in your build.gradle file.
dexOptions {
jumboMode = true
}
For more info on the string limit see this post What does 'String count' mean in Dex file Android?

Categories

Resources