I am working in Android Studio 2.3 and I want to make use of a library I found on github (https://github.com/henrychuangtw/Android-ChatHead) and there is no Jar file. In settings.gradle I have declared the directory in which the library resides in like this:
include ':app'
include ':Android-ChatHead'
project(':Android-ChatHead').projectDir=new File('/Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads')
And I have also added the library to the build.gradle dependencies:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Android-ChatHead')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
After this, if I sync, I get this error:
Gradle sync failed: Project :app declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :Android-ChatHead. Consult IDE log for more details (Help | Show Log)
If I add /app to the end of the file path in settings.gradle, I get the following error:
Error:Dependency Doritest:Android-ChatHead:unspecified on project core resolves to an APK archive which is not supported as a compilation dependency.
File: /Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads/Android-ChatHead/app/build/outputs/apk/Android-ChatHead-release-unsigned.apk
I cannot figure out what I should do.
You cannot add dependencies like that as far as i know
I assume there is no jar for dependency you want to use, so you will have to add Android-ChatHead
as module
In order to do so follow these steps:
In the Source directory box, type or select the directory of the module(s) that you want to import:
If you are importing one module, indicate its root directory.
If you are importing multiple modules from a project, indicate the project folder. For each module inside the folder, a box appears and indicates the Source location and Module name. Make sure the Import box is checked for each module that you want to import.
Type your desired module name(s) in the Module name field(s).
Click Finish.
In your settings.gradle add
include ':app', ':Android-ChatHead'
In dependencies section of you app build.gradle add
compile project(':Android-ChatHead')
clean/Build the project
What P.Lorand is doing is referencing an module rather than copying so any edits he makes on the module affect all other applications referencing the module.
With the Ivan Milisavljevic way, a module gets copied to an application. Edits made on the imported module is effective only within the application;sometimes good idea, sometimes an annoyance.
Application has application root and an application module within it;normally named app.
Module's root is the module itself.
changing this:
project(':Android-ChatHead').projectDir=new File('/Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads')
to
project(':Android-ChatHead').projectDir=new File('/Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads/moduleName')
might help.
Also if you are converting an application to a module, do make sure to rename app
, two modules with the same name app
is a promise for disaster.
It contains an app folder, so it's an application and not a module.
build.gradle contains a line apply plugin: 'com.android.application'
, so the application
bit needs to be replaced with library
.
Comment out applicationId "henrychuang.tw.chatheadmsg"
.
Rename the module name app to something else; I've never done it manually, with android studio ctl+alt+r on app folfder in Project tab.
Then you should be fine. Try importing by copy first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With