Reputation: 139
I have one project (MyProject) in which there is one library(customlib) module is there, that library module is using one jar file commontask.jar which i imported int module. i also want to use same jar file in android project. I imported that module(customlib) in MyProject but if i tried to access class(CustomActivity.java) of custom lib then it giving error can not access CustomActivity.java.
customlib gradle file
apply plugin: 'com.android.library'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/customtask.jar')
}
Myproject gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':customlib')
}
if i import that customtask.jar in that project, and when i generate apk its giving error
Program type already present: com.task.common.Helper
Upvotes: 2
Views: 3828
Reputation: 2178
Original Question (Before Update)
How to import .jar file in module and also in android application?
Answer:
For .jar files you can add them in app folder of Android Studio Project
Then Open you Android Studio Project as Project View and inside app folder, Right click on jar file and select add as library.
1. Open Android Studio in Project View
2. Open app >> create libs package by right clicking on app. add you .jar file inside libs.
3. Then right click on your .jar file and add it as library
Upvotes: 4