I am developing an android app. I have added a new project to my gradle build as follows....
In the build.gradle I have added...
android {
dependencies {
implementation project(':code-scanner')
}
...
}
In the settings.gradle I have added...
include ":code-scanner"
project(':code-scanner').projectDir = new File(settingsDir , "../External/code-scanner")
The project builds fine. But I would like to be able to browse the source, and add breakpoints to the code-scanner project, but it does not show up in Android Studio.
I have tried importing module , but the folder is missing from the subsequent select folder dialog.
How can I add this code to android studio, and set breakpoints and debug....
Just in case. Based on Android Documentation dependencies should be defined outside android block. Maybe Gradle Build figures out your code, but your Android Studio can't find source code of your library.
What version of Android Studio are you using?
1- Make sure you put implementation project(':code-scanner') in app level build.gradle file
2- dependencies block should not be inside android block:
Not like this:
android {
dependencies {
implementation project(':code-scanner')
}
}
But like this:
android {
...
...
}
dependencies {
implementation project(':code-scanner')
}
I don't know which IDE you are using but most IDEs like Android Studio or IntelliJ look like the pictures below.
Or you can view your folder structure in Project view like this:
If you didn't accidentally delete it, it should be there.
The actual problem is the location of the project, which is outside of the root project directory:
include ":code-scanner"
// project(':code-scanner').projectDir = new File(settingsDir , "../External/code-scanner")
Better add it as a library module within the root project, then the code should be within IDE scope.
If you don't want to move the project into there, you could put a built artifact into the libs directory.
Adding a symbolic link might also work out (it's rather a file-system issue than a Gradle issue).
'code-scanner' project you have to add as a library to the current project,for that in code-scanner build.gradle file you have to add
apply plugin: 'com.android.library'
please check if it is missing.
Related
I have two projects with directory structure as follows
./MyProject
./SomeOtherProject
and i want to add SomeOtherProject to MyProject by writing the directory structures to gradle. (Am not using android studio)
e.g when I add AnotherProject to libs directory
./MyProject/app/libs/AnotherProject
then I add this to ./MyProject/app/build.gradle
api project(':app:libs:AnotherProject:app')
The project is successfully imported.
Now I have project directory structure
./
./MyProject/
./SomeOtherProject/
and I want to add SomeOtherProject to MyProject by hard coding to the build.gradle files
I have tried this but its a failure, projectis still not imported.
./MyProject/settings.gradle
include ':app';-
include ':SomeOtherProject';-
project(':SomeOtherProject').projectDir = new File(settingsDir, '../SomeOtherProject/app');-
Then in my MyProject/app/build.gradle
dependencies {
implementation ':SomeOtherProject'
}
I have also tried this in ./MyProject/app/build.gradle
dependencies {
api project(':app:..:SomeOtherProject:app'
}
If question is not clear, I will update, please help.:(
Just add this to your ./MyProject/app/bulid.gradle
dependencies {
api project(':..:SomeOtherProject:app')
}
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip
The title is a little misleading but I honestly don't know how to word it in any other way. This is my project structure:
I want to use the highlighted (fasteranimationscontainer-master) in my current app that I'm working on. I imported it by putting the jar file in my library folder then adding it to my library through Android Studio. But I try to create an object of that imported library, it doesn't show up/import.
I'm still learning how to use android studio so any help would be much appreciated!
1. Library with only the Source Code
To include a library with only the source code (like FasterAnimationsContainer) to your project, you only need to import it as a module from File -> New-> Import Module in Android Studio:
There should be a dialog for the project folder, enter the path where your library reside.
Then you need to add the module to your app build.gradle as a dependency:
android {
...
dependencies {
...
compile project(':fasteranimationscontainer')
...
}
}
Now you can use it in your project.
2. Library from Maven or JCenter
To add dependencies to your project where the library has uploaded to maven or jcenter, you need to modify your app build.gradle file and add extra lines configuring the packages you require. For example, for certain Google or Android, dependencies look like:
android {
...
dependencies {
// Google Play Services
compile 'com.google.android.gms:play-services:6.5.+'
// Support Libraries
compile 'com.android.support:support-v4:22.2.1'
}
}
Try to always read the library README first.
Suggestion:
If you still learning using Android Studio, you can read Using Android Studio. Then read Getting Started with Gradle, because Android Studio is tightly related with Gradle.
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip
I'm trying to build a project dependent on ActionbarSherlock in Android Studio.
After much reading I've ended up having a working build, but only if I nest the ABS project inside my main project like so:
MainProject
MainProject\ABS (copied here and then used import module)
MainProject\MainModule (the one created by the wizard)
I had to edit the various Gradle files, settings.gradle is as follows:
include ':OnTop'
include ':ActionbarSherlock'
I fixed the dependencies in the build.gradle files accordingly.
This is suboptimal, I think. Surely I don't want to replicate the ABS module in every new project that uses it? What should I be doing instead?
Every step are here : How do I add a library project to Android Studio?
If you want to more about gradle see the Google I/O conference by Xavier Ducrohet on youtube : http://www.youtube.com/watch?v=LCJAgPkpmR0
I searched this issue enough and finally these are my results:-
This sample project
-> project root
d:\asprojects\thisproject
-> module
d:\asprojects\thisproject\MyModule
-> libraries
d:\asprojects\lvl
d:\asprojects\MyLibrary
-> jars
D:/asprojects/android-support-v4.jar
D:/asprojects/GoogleAdMobAdsSdk-6.4.1.jar
-If you want to use external (outside the project) libraries then the settings.gradle has to point to it like so:-
settings.gradle
include ':lvl', ':MyLibrary', ':MyModule'
project(':MyLibrary').projectDir = new File('D:/asprojects/MyLibrary')
project(':lvl').projectDir = new File('D:/asprojects/lvl')
-Then you need to setup the build.gradle for the MyModule correctly like so:-
build.gradle
dependencies
{
compile files('D:/asprojects/android-support-v4.jar')
compile files('D:/asprojects/GoogleAdMobAdsSdk-6.4.1.jar')
compile project(':lvl') compile project(':MyLibrary')
}
-But the IDE will not like these absolute paths and will say not found.
-But gradlw from commandline work justs fine:-
gradlew clean
gradlew build
gradlew installRelease
etc