Replacing/Overriding classes of the android-sdk - java

I'm confused with the compilation under Android.
I've a library using those dependencies :
compile('org.apache.httpcomponents:httpmime:4.3') {
exclude module: 'httpclient'
}
//we need the org.apache.http.entity.ContentType class
compile('org.apache.httpcomponents:httpcore:4.3')
My misunderstanding is that it compiles and seems to run properly, but I would expect a compilation error since :
Android SDK contains many classes with exact same name as the classes in httpcore
Here are my questions :
Why is there no UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added:... during compilation ?
How can I know which version of the duplicate classes is used at runtime ?
I'm using build tools 19 :
buildToolsVersion "19.1.0"
compileSdkVersion 15
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}

Use the official Apache HttpClient port for Android instead of the stock version

Related

targetSDKVersion, minimumSDKVersion, and compileSDKVersion for specific device

I'm programming for one specific device and I'm having trouble understanding how I should be setting minsdkversion, compilesdkversion, and targetsdkversion. I want to get a compiler error when I'm using a library that doesn't exist for API level 25. Here's what I gatherered. Minsdkversion prevents calling API that doesn't exist for API version. Compilesdkversion should always be the latest version. Targetsdkversion is what the app was tested against (don't understand what this means).
minsdkversion-25
compilesdkversion-28 (needed for AndroidX)
targetSDKversion-25
Version settings
Among those version settings, only minSdkVersion takes effect to detect API level error. If you'd like to know details of the version settings, see documentation.
How to let build system report API level error
For release builds, place "lintOptions" in app/build.gradle and mark "NewApi" as "fatal". Then lintVitalRelease gradle task reports error during compilation.
android {
lintOptions {
fatal "NewApi"
}
compileSdkVersion 30
defaultConfig {
minSdkVersion 25
targetSdkVersion 30
:
}
:
}
Checking API level manually
In debug builds, the lintOptions above doesn't have any effects because the lint is not included in debug build tasks (there is no lintVitalDebug gradle task). So rather, after coding, run "code inspection" manually to detect all the NewApi problems in your code. If incompatible API uses found, you'll see "calling new methods on older version" error in the inspection result.

Failed to find style 'coordinatorLayoutStyle' in current theme In Android Studio 3.1

The Android Studio 3.1 layout preview fails to find style 'coordinatorLayoutStyle' in the current theme.
Failed to instantiated one or more classes.
Exception shown are :-
java.lang.ClassNotFoundException: android.view.View$OnUnhandledKeyEventListener
This happened due to use of alpha version SDK 28
We need to change the android { ... } in "build.gradle" in app file
compileSdkVersion 28 to compileSdkVersion 27
targetSdkVersion 28 to targetSdkVersion 27
Also, try to change implementations like
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' to
implementation 'com.android.support:appcompat-v7:27.1.1'
Hope this works!
For Android Studio v3.1.*, in addition we need change:
implementation 'com.android.support:design:28.0.0-alpha3' to
implementation 'com.android.support:design:27.1.1'
you can fix this issue by adding this script to the app module build.gradle, in the android section
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "27.+"
}
}
}
}
This appears to be a bug in the current version of Android Studio (3.1.3) as I was encountering the same thing. I downloaded the beta build from here and opened my existing project and the errors disappeared.
https://developer.android.com/studio/preview/?utm_source=android-studio
Not exactly a fix but hopefully it will get you back up and running.
Update
1. com.android.support:appcompat stable version 28.0.0 is released. So no need to downgrade version. Just use 28.0.0.
def supportVersion = "28.0.0"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
You can ignore design library if you don't need it.
2: You also need to update your compileSdkVersion & targetSdkVersion to remove some gradle warnings.
compileSdkVersion 28
targetSdkVersion 28
Never use alpha versions of any library, because alpha, beta and rc
versions may have bugs. And you don't want to face these types of errors often.
Important Suggestion
I suggest you migrate to androidx because android will not update support library after 28.0.0, all updates will be available to androidx package only. Check related answer.
This is fixed in Android Studio 3.2.
Go to app/res/styles and change the Theme.AppCompat.Light.DarkActionBar for this one Base.Theme.AppCompat.Light.DarkActionBar

Android project error

I am trying to run an app that has a Google Maps Activity on my phone. My phone's running on Android 4.1.3 and the Minimum SDK for my project is API 15: Android 4.0.3
I just created the project on Android Studio and tried to run it on my phone. But it won't run and I am keep getting this error. Can someone tell me how to solve this?
That error probably means that you are using too much libraries. And because you are trying to use google maps I'm guessing you included everything google.
Try to just use the libraries you need.
For maps use this:
dependencies {
com.google.android.gms:play-services-maps:9.2.1
}
Reading material:
https://developers.google.com/android/guides/setup
You need to configure your gradle for multidex.
Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code snippet:
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
See more on same link which you are refering : https://developer.android.com/studio/build/multidex.html#mdex-gradle
You can also see some related question for same error:
How to enable multidexing with the new Android Multidex support library
Android java.exe finished with non-zero exit value 1

Getting error in Android Studio 2.1 with java 8

Currently I am using java 8 with latest android studio 2.1
Here is my build.gradle file
android {
compileSdkVersion 22
buildToolsVersion "24rc3"
defaultConfig {
applicationId "com.name"
minSdkVersion 10
targetSdkVersion 19
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
.......
}
I am getting the below compile time error that I have no clue
Error:com.android.jack.frontend.FrontendCompilationException: Failed
to compile at com.android.jack.Jack.buildSession(Jack.java:892) at
com.android.jack.Jack.run(Jack.java:472) at
com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:102)
... 8 more Warning:Exception while processing task
java.io.IOException: com.android.jack.api.v01.CompilationException:
Failed to compile :oTT:compileDebugJavaWithJack FAILED Error:Execution
failed for task ':oTT:compileDebugJavaWithJack'.
java.io.IOException: com.android.jack.api.v01.CompilationException: Failed to compile Information:BUILD FAILED
Please feel to ask if you need some details.
I had this error too, and what I found was that the error itself was masking another compilation issue. Look at your Console Messages carefully and see if there is something else not compiling. Once I solved the underlying issue with my own code, this error magically disappeared. Hope this helps.
Try to use next values:
compileSdkVersion = "android-N"
buildToolsVersion = "24.0.0 rc3"
you can try
compileSdkVersion 23
buildToolsVersion '24.0.0-rc3'
note the dash before rc3. This is according to http://developer.android.com/preview/setup-sdk.html under the section "Update an existing project"
I am using 23 just for the lambda.
the following link shows the Supported Java 8 Language Features and APIs https://developer.android.com/preview/j8-jack.html
I think we are all looking mostly at the same answer. To be precise I'd say "make sure the buildToolsVersion = "[version]" is the same as the [version] in the error".
For some this will be 24.0.0
Some java 8 features only support Android N. read android docs
http://developer.android.com/preview/j8-jack.html#configuration
When I use Default Methods on sdk23, I got this error too. so update your sdk version to Android N.

java.lang.NoSuchMethodError: android.support.v4.content.ContextCompat.checkSelfPermission [duplicate]

I am trying to make runtime permissions backward compatible with older devices but using the support library i cant find checkSelfPermission() static call in ContextCompat class, but its documented here
Here is my project gradle settings:
defaultConfig {
applicationId "org.myprogram.cool"
minSdkVersion 16
targetSdkVersion 23
versionCode 39
versionName "3.0"
}
and here is the dependencies:
compile 'com.google.android.gms:play-services:+'
compile 'com.squareup:otto:1.3.5'
compile 'com.android.support:appcompat-v7:22.1.1'
any idea what i am missing ?
checkSelfPermission() didn't get introduced into the native Context until API 23. So you will need to use at least version 23.0.0 of the support library.
You should change this
compile 'com.android.support:appcompat-v7:22.1.1'
to this
compile 'com.android.support:appcompat-v7:23.0.1'
If you have migrated from eclipse adding the below line wont work
compile 'com.android.support:appcompat-v7:23.0.1'
While migrating, it adds appcompatv4 as an external dependent library.
Make sure you have deleted the appcompatv4 library from the libs folder and then it should start working
Make sure class exampleActivity class is extending from AppCompatActivity.
Make sure that your minSdkVersion is 23 in the build.gradle file.
Sync your gradle after making this change.
That should work.

Categories