org.apache.http jar class not found in android studio projects - android

i include following jars see below image.
I want to integrate json web service so i import below jars
apache-mim44j-0.-6.jar
gson-2.1.jar
httpmime-4.0.1.jar
json_simple-1.1.jar
build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "pkg.android.myapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}
when i set above structure my jar file is not getting in my class file any idea how can i solve this problem?your all suggestions are appreciable.
EDIT
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "pkg.android.myapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}

Apache HTTP Client was removed since API level 23:
This preview removes support for the Apache HTTP client. If your app
is using this client and targets Android 2.3 (API level 9) or higher,
use the HttpURLConnection class instead. This API is more efficient
because it reduces network use through transparent compression and
response caching, and minimizes power consumption. To continue using
the Apache HTTP APIs, you must first declare the following
compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
Android is moving away from OpenSSL to the BoringSSL library. If
you’re using the Android NDK in your app, don't link against
cryptographic libraries that are not a part of the NDK API, such as
libcrypto.so and libssl.so. These libraries are not public APIs, and
may change or break without notice across releases and devices. In
addition, you may expose yourself to security vulnerabilities.
Instead, modify your native code to call the Java cryptography APIs
via JNI or to statically link against a cryptography library of your
choice.
Reference:
https://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client

You can use this
link to download all libs. and then include
httpclient-4.5.1.jar
httpcore-4.4.3.jar
and if get confilcts use these lines in buil.gradel
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
if get any more, click on highlited import and Alt+Enter.
got solved by this

Related

Android Instant App with Native C++ Library not publishing to device/simulator running Android N

Is there a way to get an Android Instant App working with a native C++ library?
I'm attempting to publish an Android Instant App to a device/simulator, but ran into problems with my native C++ library. It publishes fine as an installable app, but fails to find the library when published as an Instant App.
To eliminate any other issues, I started a new project in Android Studio 3.0 (Canary 1 171.4010489) with the new project wizard and selected the following settings:
First Page:
Include C++ support checked
Second Page:
Phone and Tablet selected
Include Android Instant App support checked
Sixth Page:
C++ Standard set to 'C++11'
Exceptions Support (-fexceptions) checked
Runtime Type Information Support (-frtti) checked
The resulting project will publish as an installable app (showing the 'Hello from C++' screen), but not an instant app... it gives the following error that it can't find the library, which is the same error I get in my actual app's project:
couldn't find "libnative-lib.so"
Full error:
05-24 17:48:30.316 7519-7519/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycompany.instantapp, PID: 7519
java.lang.UnsatisfiedLinkError: byc[DexPathList[[zip file "/data/user/0/com.google.android.instantapps.supervisor/files/atom-cache/com.mycompany.instantapp/atom-download--feature-1495662507463/feature.jar"],nativeLibraryDirectories=[/data/user/0/com.google.android.instantapps.supervisor/files/native-lib/com.mycompany.instantapp, /system/lib, /vendor/lib]]] couldn't find "libnative-lib.so"
...
I'm pasting the relevant gradle files below (all generated by Android Studio):
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
defaultConfig {
applicationId "com.mycompany.instantapp"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':feature')
implementation project(':base')
}
base/build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
feature project(':feature')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
feature/build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':base')
testCompile 'junit:junit:4.12'
}
instantapp/build.gradle:
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':feature')
implementation project(':base')
}
Updates:
I've filed an issue with Google:
Link: Google Issue Tracker
Though I feel like the tools to make this happen are already available (Gradle, CMake, NDK, etc)
Also thanks #Anirudh for letting me know that this is a known issue on Android N.
Does publishing an Instant App with no C++ library work on my device?
Yes... if I create a new Android Studio project with only Include Android Instant App support it publishes to my Samsung Galaxy 7S and shows the 'Hello World!' screen.
Does publishing a signed APK work?
Generating a signed APK works, and upon inspection the native C++ library is bundled with the feature-debug.apk but not the base-debug.apk. This is what I would expect given the gradle configuration, but doesn't explain why it won't publish to a device/simulator.
I haven't tried sideloading these APKs... but I'm skeptical if that is even possible given that the Instant App is never installed... ex: how would you even launch it after sideloading it (click a url?)
Does adding the C++ library to both APKs work?
I've tried adding the externalNativeBuild gradle properties to both the base/build.gradle and the feature/build.gradle files, but the same error still occurs. I verified that the native C++ library is then included in both APKs by inspecting both the feature-debug.apk and the base-debug.apk after generating a signed APK.
modified base/build.gradle:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0 rc2"
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "../feature/CMakeLists.txt"
}
}
}
dependencies {
feature project(':feature')
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
Does publishing a signed APK work?
Android Studio 3.0 preview Generate Signed APK feature has a bug currently where the final zip doesn't include all feature apks. Use Gradle SigningConfig in each feature module's gradle file to sign your feature apks
Does adding the C++ library to both APKs work?
Not required. Adding to base feature apk should be enough
The actual crash is known issue with NDK support for Android Instant Apps on Android M/N. The app works on Android O emulator

How do I use android.support.transition?

I want to run my app, which uses transitions on an android device with Jelly Bean 4.2.2, API 17. In the build.gradle:app targetSdkVerion is set to 24, minSdkVersion to 16.
When launching the app on my device I get the error Could not find class android.transition.Transition
On Android Developers theres a package called android.support.transition mentioned, but I don't know how to use it, when I insert it in my build.gradle I get an error, "Could not find com.android.support:transitions:24.1.1.
Do I need to change the values, and if so, how?
My build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "user.example"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:transition:24.1.1'
}
You need to download or update support library from SDK Manager. This is link from Android Developer website :
Setup Support Library
Then you can use the support transition library. Note that if you want to use the TransitionManager class from this support library, be sure to import the support library version ('android.support.transition.TransitionManager')

google maps api sdk version error?

It's my code sample. When I firstly build my code, it results in so-called dex error. I added multiDexEnabled property to my gradle setting, but it results in java heap memory overflow. I increased its max size, and finally got builded. However, another error occurred...... what is the problem? android adk version?
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "belobster.earthquakealert"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services:9.6.1'
}
emulator image.
Check whether play services is available on the emulator, you should consider using physical device for these kind of testing purposes since maps require location services quite often.
download gapps-lp-20141109-signed and install in genymotion
If you want to test it into Genymotion only then , Genymotion provide support for play service
So please check it. It's work for me.
Thank you.

how to use marshmallow in Android studio

I am using Android studio and i want to use Marshmallow API and AppCompatActivity. When I created a new project the build.gradle contained the below lines but I receive error at R class which says not a symbol.
Please let me know how to correct the build.gradle to get the App work.
gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.com.myapplication"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
}
Click on Build->Clean Project and that will perform a gradle clean
Update your Android SDK Manager Install all component of Android 6.0 (API 23)
R file can be erased due to many reasons, try rebuilding your project(which is the most common issue) and other issues may include any syntax error or inappropriate file permissions in work space, the exact error report can help address the issue better.

Adobe Creative SDK integration Android error

Following the given documentation: https://creativesdk.adobe.com/docs/android/#/articles/imageediting/index.html
I proceeded with my project setup but when I go on to edit the build.gradle file for my app and add the compile project(':creativesdk:CreativeSDKImage') dependency and rebuild, the build fails showing the Error:Configuration with name 'default' not found.
Here is my settings.gradle file-
include ':app'
include ':creativesdk'
include ':creativesdk:CreativeSDKImage'
include ':creativesdk:Foundation:CreativeSDKFoundationAuth'
project(':creativesdk').projectDir = new File
("C:\\Users\\Neel Raj\\Desktop\\AdobeTest\\creativesdk-repo\\com\\adobe/creativesdk")
project(':creativesdk:CreativeSDKImage').projectDir = new File
("C:\\Users\\Neel Raj\\Desktop\\AdobeTest\\creativesdk-repo\\com\\adobe/creativesdk/CreativeSDKImage")
project(':creativesdk:Foundation:CreativeSDKFoundationAuth').projectDir = new File
("C:\\Users\\Neel Raj\\Desktop\\AdobeTest\\creativesdk-repo\\com\\adobe/creativesdk/Foundation/CreativeSDKFoundationAuth")
The build.gradle file -
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.neelraj.adobetest"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile project(':creativesdk:CreativeSDKImage')
}
I cannot figure out a way to fix this. I'm not even sure if I'm doing everything correctly. But I have followed the documentation step by step.
Any detailed way to setup the image sdk would be very helpful
I got the same problem with this guide.
Just see here : Trying to make an Android Studio Application with Adobe Creative SDK Image Editing, cannot get libraries compiled in gradle
Follow the steps to configure the SDK.
After that you can follow the rest of the mentioned tutorial.
What helped me was to look at the sample code from Android Creative SDK "CreativeSDKImageSampleApp" and after some hours it worked for me

Categories

Resources