I am trying to build an app which is composed out of separate library projects.
To do this, I'm trying to make a proof of concept which is supposed to be as following:
I tried to keep the project as simple as possible. The projects contents do not matter!
All that matters is the dependencies between the projects!
The result should be that MainProject will print out Something Another String!
I have tried all from .JAR files to .AAR files, but the best I got was
with the dependency in red. I added the StringExtender.aar file to StringReturner, and then the StringReturner.aar file to the MainProject.
When I do this I get the following Exception:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/erik/stringextender/StringExtender;
What is the right way to setup a simple proof of concept like this? I can't seem to find anything related to a library project having a dependency. It's all 1 level deep!
Any help is welcome!
EDIT SHOWING GRADLE BUILD FILES
StringReturner:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':StringExtender-lib-debug')
}
MainProject:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.erik.erikpoc10"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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 project(':StringReturnerLib-debug')
}
Use the following tutorial - Creating libraries for Android applications
See a working example project on my Github
The most important steps taken were:
8.3. Create library module.
8.6. Define dependency to the library project.
Do not forget to import the library class you want to use, for example:
In MainProject: import com.example.stringreturner.StringReturner.
In StringReturner: import com.example.stringreturner.StringExtender.
The info below is based on the image you provided:
The library methods are not static so don't forget to make an actual object.
So StringReturner should make a StringExtender object, And MainProject should make a StringReturner object first!
And finally, I think it's a typo but both libraries have the class StringReturner. This will not work in the StringReturner library for obvious reasons.
I should also note that I used Android Studio 2.0 and I did not touch .JAR files nor .AAR files. I merely created two library modules and one app. Then configured the Project Structure -> Dependencies by adding Module Dependencies.
Related
I came across a problem while implementing an Android plugin for Unity based on EasyPermissions. The issue was due to
Caused by: java.lang.ClassNotFoundException: Didn't find class "pub.devrel.easypermissions.EasyPermissions$PermissionCallbacks"
as the relevant classes were not packed by Android Studio into my AAR file.
I tried various ways:
Just compile in Android Studio and hope the resulting AAR will be fine FAIL
Download an AAR from jCentral and add it to Unity - FAIL
So finally I unzipped the EasyPlugin AAR and took the classes.jar file thats inside and added this to Unity. This worked. Yet its quite a manual process.
What is the tinly little bit I need to add to my gradle file to get this done automatically?
I am using:
https://github.com/googlesamples/easypermissions
Unity 2017.1 (should not matter)
Android Studio 2.3.3
Gradle task used: build->assemble
My Gradle File:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "27.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:26.+'
testCompile 'junit:junit:4.12'
compile 'pub.devrel:easypermissions:1.0.1'
provided files('unity/classes.jar')
}
PS. There was a second issue when overriding UnityPlayerActivity but for that a clause provided instead of compile was the solution.
Check above comments.
If you use an external library its enough to add its AAR into Plugins/Android directory in Unity.
For some reason I added it in a way that went unnoticed by Unity and Unity was not adding it into resulting APK file.
I got a project which I imported from Eclipse to Android Studio. In Eclipse everything worked well.
It contains a main module (a project in Eclipse) which uses packages from a library module (library project in Eclipse). Since the migration did not went well, I have created a library module manually and just copied all the source code to the newly created module.
The problem is that the main module doesn't seem to find the packages from the library module and when I rebuild the project I get errors like "package bla bla does not exist".
Here is the main module gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.pointer.mamagoose"
minSdkVersion 9
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':linphoneclean')
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile files('libs/firebase-client-android-2.5.0.jar')
compile files('libs/apache-httpcomponents-httpclient.jar')
compile files('libs/apache-httpcomponents-httpcore.jar')
compile files('libs/android-support-v7-recyclerview.jar')
}
linphoneclean is the library module.
The entire project's settings.gradle:
include ':linphoneclean'
include ':tigris'
This is the build.gradle of the library module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.6.2'
compile files('libs/commons-lang3-3.4.jar')
compile files('libs/linphone.jar')
compile files('libs/firebase-client-android-2.5.0.jar')
}
The structure of the library module includes for example folder:
src/main/com/pointer/linphone (and inside there are all the java files with a deceleration of package com.pointer.linphone, Yet I still get an error saying >"package com.pointer.linphone does not exist).
What am I doing wrong?
After fighting with the same issue for hours here is what worked for me.
I've created a fresh project with blank activity, added a library module with a dummy class, defined the dependency. Verified that it works by importing the dummy class in the app. Then I copied all my relevant code from the real project.
My thinking is that it was probably issue with IDE's iml files, since starting from scratch and copying stuff over worked.
See properly source file contains both java folder and res folder,add java files in java packages and res in res folder.Add Activity name in Manifest file see here ,add necessary libraries files in Gradle file.Clean and rebuild the project in the Android studio.
https://developer.android.com/guide/topics/manifest/manifest-element.html
Maybe you can check if the library's AndroidManifest has defined the package correctly, like:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.pointer.linphone">
I'm a beginner in android developing whith Android Studio.
I'm trying to include the htmlcleaner library in my project, but when I rebuild the project, Android Studio return this Error
Error: COnfiguration whit name 'default' not found
I added in the root folder of my project the library folder, so I added this line in settings.gradle
include ':htmlcleaner'
and this line in build.gradle
compile project (':htmlcleaner')
Is there anyone who can help me? thanks
to include many informations, I post the build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.rob_company_domain.sunshine"
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project (':htmlcleaner')
}
If you want to add your htmlcleaner library to your project in Android studio, you can do it in three standard ways. Please read this link https://stackoverflow.com/a/35369267/5475941. In this post I explained how to import your JAR files in Android studio and I explained all possible ways step by step with screenshots. I hope it helps.
We are moving our years old Android project to Android Studio and away from eclipse.
The problem is that we have some jar files that use code specific to the devices that we work on. (I know! Don't say it. I'm working with the whole team to move past this.) Since these JAR files override some of the bluetooth code, they have to go ahead of the SDK in the dependency list for the thing to build. (These libraries are for compile time only.)
While on eclipse, Android SDK was a full blown plugin and I could control the libraries absolutely and make sure these libraries were first. With Android Studio, I don't seem to be able to control the position of the SDK in the dependency path.
I have edited the app.iml file and changed the order of the orderEntry tags at the bottom. This appears to have fixed the problem inside the IDE and it appears to be building fine now.
I am still unable to build the project using gradle.
Based on feedback here, here is my current build.gradle
apply plugin: 'com.android.application'
configurations { razrBuild }
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
razrBuild fileTree(dir:'assets',include: ['*.jar'])
provided files('assets/BluetoothGattService.jar')
provided files('assets/BluetoothGatt.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile files('libs/android-support-v4.jar')
compile files('libs/myapp-util.jar')
}
project.afterEvaluate {
project.android.applicationVariants.all { v ->
v.javaCompile.classpath += configurations.razrBuild
}
}
Any ideas?
Put jars you want to compile time only into a folder(For my example : extlib)
Then add some configurations to build.gradle
configurations { providedCompile }
dependencies {
providedCompile fileTree(dir:'extlib',include:['*.jar'])
}
project.afterEvaluate {
project.android.applicationVariants.all { v ->
v.javaCompile.classpath += configurations.providedCompile
}
}
I'm trying to set up Double Espresso, but that's probably not relevant here. What I'm trying to do is to set up a project in Android Studio using Gradle.
I'm very new to Gradle and build tools in general, though I've successfully used Maven before. Despite an hour of searching I can't find an answer to a very simple question.
In Jake Wharton's instructions it says
No more fumbling with local jars or dependency conflicts. Pull it in with one line:
androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3'
Pull in where? Where do I put/execute that command to import the project? In the command prompt? Do I put it in one of the scripts?
Thanks for any help.
You have a build.gradle file inside your app folder. In that file you can configure your project, "dependencies" and other options. It's very similar to maven. You have another build.gradle file in your root folder from your project. This conf file is more general and call the other build.gradle file.
e.g I have in one of my projects
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.acostela.example"
minSdkVersion 17
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:20.+'
compile "com.android.support:gridlayout-v7:18.0.+"
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'commons-net:commons-net:3.3'
compile 'net.sf.opencsv:opencsv:2.3'
}
Dependencies here are similar to maven and the use in that tool of "/".
Gradle take libs from repositories in the same way of maven. In fact you can use the maven repository. You have a tab with the gradle sentence to download libraries.
http://mvnrepository.com/artifact/com.squareup.assertj/assertj-android/1.0.0