I'm trying to share 2 external dependencies between 2 modules in Android Studio.
The 2 dependencies are Twitter Core and Twitter4j (a Twitter library extension I'm experimenting with).
Here is the project structure:
Root project 'cineios-test'
+--- Project ':app'
\--- Project ':cineio-broadcast-android-sdk'
I set up the dependencies in my app build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.lgorse.cineios_test"
minSdkVersion 18
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'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':cineio-broadcast-android-sdk')
//compile project(':cineio-broadcast-android')
//compile 'io.cine:cineio-broadcast-android-sdk:0.0.9'
compile ('org.twitter4j:twitter4j-stream:4.0.2'){
transitive = true;
}
compile('com.twitter.sdk.android:twitter:1.1.1#aar') {
transitive = true;
}
}
Here is the build.gradle file for the module, which is cineios-android-sdk:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
// applicationId 'io.cine.android'
minSdkVersion 18
targetSdkVersion 19
versionCode 11
versionName '0.0.11'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.google.guava:guava:16.0'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
}
Finally here is settings.gradle:
include ':app', ':cineio-broadcast-android-sdk'
project(':cineio-broadcast-android-sdk').projectDir = new File('cineio-broadcast-android/cineio-broadcast-android-sdk')
I know there are answers on SO but they refer adding local libraries as modules - but since these dependencies are remote I'm not sure how to adapt the hints to this situation.
I did try adding the dependencies to the other module (cineios-android) but a) it seems ridiculous to double them up like that and b)that would imply registering a new app in the Twitter API, which will probably lead to errors.
The correct approach really is to specify the dependencies in both the main app and the module.
I did try adding the dependencies to the other module (cineios-android) but a) it seems ridiculous to double them up like that and
There's really nothing ridiculous about it. Don't think of it as trying to "share" the dependency between the main app and the module. Look at it this way: your module depends on Twitter4j and Twitter Core. If you were to reuse that module in a different application, the module should be self-contained and should be able to specify its own dependencies without the parent project needing to set them up. Making all its dependencies explicit does this.
If the parent app also depends on Twitter4j and Twitter Core, and if you use the Maven Coordinate-style remote dependency specs as you have, the build system will ensure that only one copy actually gets linked into the app, so everything will be okay.
b)that would imply registering a new app in the Twitter API, which will probably lead to errors.
I'm not familiar with how that works, so I can't comment on it other than to say that if their API is well designed, hopefully just including the library shouldn't imply something like that. If you're having problems, clarify your question or ask a new one.
In your build.gradle add dependency like below:
dependencies {
compile 'org.openimaj:twitter:1.3.1'
}
You can also use belowed link for more reference :
Gradle Please
Related
I'm trying to get into developing using android studio, so I recently tried to run a simple login-activity app on it. Basically, what I did was just run the setup for a new android studio project, and selected loginactivity as my default screen. I configured the emulator and hit sync gradle, but it gave me the following response:
image
I downloaded the repository that was required and tried to sync the gradle again, but it again asked exactly the same thing! Please help!
my gradle file for the app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.fyp.fingerpay"
minSdkVersion 23
targetSdkVersion 27
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.google.android.gms:play-services:10.2.6'
compile 'com.android.support:appcompat-v7:27.+'
}
I think you have forgot to add maven repository in your app gradle file.
Try by doing these steps.
Open the build.gradle file for your application.
Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example:
allprojects {repositories {jcenter()maven {url "https://maven.google.com"}}}
Avoid using + in your dependencies as it android studio will try to update dependencies every 24 hours.
Also replace compile by implementation for low APK size.
I try to add Mosby library to my pet project, but i cannot understand how to include it to project?
I try to add mosby by add as module-> add as Gradle project, but it not compile.
please, can you link me some tutorial how to add projects (source) into my project and how to use it then (i mean a access to libs classes from my code)?
Thank you!
P.S. Project stores at K:\PetProject. Mosby at: K:\mosby.
settings.gradle (of my project):
include ':app', ':mvp', ':sample-dagger2-rx', ':sample', ':mvp-common', ':viewstate', ':sample-kotlin', ':sample-flow', ':testing', ':sample-mail', ':sample-dagger1'
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta7'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle at myproject\app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "net.simplevolk.mafiagm"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/main/java/2'] } }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
}
Mosby should be added to your project by adding the following to the dependencies section in your build.gradle at myproject\app rather than as a module as how you did it.
compile 'com.hannesdorfmann.mosby:mvp:2.0.1'
compile 'com.hannesdorfmann.mosby:viewstate:2.0.1' // optional viewstate feature
As for a tutorial for using Mosby, the url at the top of the Mosby github page links to information about the library including a tutorial about how to use it. I found the walk through of the sample-mail app at http://hannesdorfmann.com/mosby/first-app/ helpful when I started using Mosby.
I am trying to debug through library code in Android Studio. But it shows unresolved symbols, i.e., red lines at lots of places.
My app build.gradle looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kuldeep.customview"
minSdkVersion 16
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
My project build.gradle file is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You're looking at the code for TextView, which is an Android platform class and not part of your app. Platform classes can refer to other "package private" classes that are not part of the visible API for an app. Android studio provides for you the ability to view platform source code like this so you can see how it works, but you can't make changes to it and you don't get access to all the actual compiled classes in the SDK.
The short story is that is regular and expected. If you were seeing this for your own app code (not platform classes or add-on libraries) then you'd have something to be concerned about.
2 possible reasons:
Gradle not synced.
Try syncing your gradle files using Gradle Sync.
SDK not updated.
Make sure your SDK is updated and that you have all the extra packages that you need installed. You can do that using SDK Manager.
I have added JakeWharton/ViewPagerIndicator by adding below statements to gradle.I am trying to use TabPageIndicator like this but it can't find import com.viewpagerindicator.TabPageIndicator although my gradle build fine after adding library.
Top Level Build.gradle:
buildscript {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
App's build.gradle:
compile 'com.viewpagerindicator:library:2.4.1#aar'
Update
Library is available here where you can download the zip
https://github.com/JakeWharton/ViewPagerIndicator
and at the website for VierPagerIndicator:
http://viewpagerindicator.com/
To add this:
Right click your Main Application ->New Module
From the More modules section ->Import Existing Project
Navigate to where you have downloaded, and extracted the zip file and select it.
This should import it and add it as a dependency for your project, unfortunately this did not get the desired project structure I wanted. So i copied the new module to the libs folder of my main module.
However this causes issues with gradle since now the project is linked incorrectly. So after i imported the new module and moved the project from a module within my main application i was prompted to add the library as a reference in settings.gradle which now looks like:
include ':app',':ViewPagerIndicator'
project(':ViewPagerIndicator').projectDir = new File('app/libs/ViewPagerIndicator')
And my Main apps build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.test.demo.myapplication"
minSdkVersion 8
targetSdkVersion 22
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:22.0.0'
compile project(":ViewPagerIndicator")
}
Additionally my project structure is:
Add your library module from project structure and sync
Today I updated to Android Studio v 1.0 and I'm getting the following error when trying to compile whatever project.
....\app\build\intermediates\classes\debug: file not found
The thing is that before updating it I had no problems. Here is the code I'm actually trying to compile.
build.grade
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "razvitrance.testnavdrawerplz"
minSdkVersion 16
targetSdkVersion 20
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:support-v13:21.0.3'
}
build.gradle (for the project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And the activity code is a simple Navigation Drawer.
Thank you for helping.
This is the erorr i'm getting.
http://gyazo.com/bdf375a160b1662ce4eb0d4e9aed8f30
Check this and this answers.
Generally, you will need to delete your grandle file and let Android Studio generate the one it thinks that it is correct, as it is being mentioned in the given posts. Happened to me too when i upgrated to newer version and that solved my problem.
It seems that Android Studio does not recognize non-alphanumeric symbols in path (cyrillic, for example). I had the same problem, and it was solved with creating project in another folder not containing cyrillic symbols in its path. In your case it may be '#' synmbol that makes a trouble