I can successfully set up Transfuse in my android project but when it comes to running the app using Android Studio, it fails. Probably because the Manifest xml has to be empty for Transfuse to take care of.
Has anyone ever got these working together?
Transfuse and Android Studio work remarkably well together. The trick is to get Transfuse integrated with Gradle. Once you get Gradle working, the build will just kick off the annotation processor and run Transfuse.
I've put together an example reference project here: https://github.com/johncarl81/transfuse/tree/master/examples/gradle
Here's the procedure to get there:
Have Android Studio generate a new Android project
Move the AndroidManifest.xml file to the root of the Android project, ie:
~/project/src/main/AndroidManifest.xml -> ~/project/AndroidManifest.xml
Setup the new AndroidManifest.xml location in the gradle.build file:
android {
...
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
}
}
Add the APT plugin:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
Finally add transfuse and transfuse-api:
dependencies {
apt 'org.androidtransfuse:transfuse:0.2.7'
compile 'org.androidtransfuse:transfuse-api:0.2.7'
}
Your final gradle.build will look like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
repositories {
mavenCentral()
}
dependencies {
apt 'org.androidtransfuse:transfuse:0.2.7'
compile 'org.androidtransfuse:transfuse-api:0.2.7'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
}
}
Edit:
Finally you probably want to add the source/apt_generated/debug or source/apt_generated/release folders as source folders under the project configuration.
Second Edit:
I updated the above example with the new Android-APT plugin
For anyone struggling with "Could not find the AndroidManifest.xml" with Transfuse 3 beta 5, I fixed by adding this to my gradle file:
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
}
}
Related
I'm developing a flutter plugin for anroid and when I try to compile my build.gradle in android studio but when it compiles it throws my the
following error:
Minimum supported Gradle version is 7.2. Current version is 7.1.
Please fix the project's Gradle settings.
Gradle Settings.
When I update the version in my build.gradle it throws me the same error but whit the new version. The project didn't generate me a gradle wrapper properties files whe i use the following commands:
fvm flutter create --template=plugin plugin-name
fvm flutter create -t plugin --platforms android .
The following is my build.gradle file
group 'com.example.scan'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 31
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
main {
jniLibs.srcDirs = ['libs']
}
}
defaultConfig {
minSdkVersion 18
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation files('src/libs/libscanner.jar')
}
go to Android Studio -> Settings -> Build, Execution, Deployment -> Gradle
then check in Gradle Project section that Use Gradle from - Specific location defined correct for your system. After apply changes and rerun build
Starting Gradle Daemon...
...
this works for me.
I have a complicated multi-project Android build. Recently upgraded to Android Studio 3.0.1 successfully. But attempting a corresponding upgrade to Android Plugin for Gradle 3.0.1 (And gradle version 4.1) breaks my project build.
There are a cascade of failure messages, but the primary ones seems to be that the http://schemas.android.com/apk/res/android is not a registered URI.
The project consists of a main project and three included subprojects. I did find a section reporting known problems with multi project builds in the Andriod Gradle Plugin upgrade documentation, but none of their recomendations resolved the issue.
Any help or advice would be much appreciated
Top level config files
build.gradle
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
jcenter()
}
}
ext {
versionName = '1.9.15-26'
versionCode = 10915260
}
settings.gradle
include ':cadpage', ':cadpage-parsers', ':cadpage-private'
Cadpage subproject / build.gradle
apply plugin: 'com.android.application'
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId 'net.anei.cadpage'
versionName project.versionName
versionCode project.versionCode
minSdkVersion 9
targetSdkVersion 23
}
dexOptions {
jumboMode = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
}
dependencies {
compile project(":cadpage-parsers")
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services-gcm:10.0.1'
}
cadpage-parsers subproject / build.gradle
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
jar {
manifest {
attributes('Implementation-Title': 'Cadpage Parsing Library',
'Implementation-Version': project.versionName,
'Main-Class' : 'net.anei.cadpage.parsers.Parser')
}
}
As it turns out, the actual problem was a misplaced item in my AndroidManifest.xml file. This is a documented issue with the upgrade. What threw me off was the IDE reporting extraneous errors about the "http://schemas.android.com/apk/res/android" URI not being registered.
While the gradle console log did, in fact, identify the correct error. The IDE popped up the intermediate manifest file where the error occured. And syntax highlighting in that file started by complaining about the unregistered URI. I had been focusing on resolving what turned out to be a spurious error report.
I am completely new to realm. I want to use realm db in my android project. I have gone through the official Realm documentation. I need to set up realm in my android project. For that I have added the gradle dependancy as
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
apply plugin: 'realm-android'
This is what they have given in documentation. But this doesn't work for me. It gives error saying Plugin with id 'realm-android' not found.
This is my build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.db.realmsample"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
}
Is my configuration correct?
Move the buildscript to your main build.gradle file (Project) , it shouldn't be there in build.gradle (module:app)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:<realm version>"
}
}
This should go to main build.gradle
First of all copy the class path dependency to build.gradle file(Project):-
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:1.2.0"
}
}
Finally, copy and paste the following code on top of build.gradle(App) :-
apply plugin: 'realm-android'
Note:- The version 1.2.0 is subjected to change on future releases.For more please check https://realm.io/docs/java/latest/
Prerequisites
Android Studio version 1.5.1 or higher
JDK version 7.0 or higher
A recent version of the Android SDK
Android API Level 9 or higher (Android 2.3 and above)
Step 1: Add the class path dependency to the project level build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:4.1.1"
}
}
Step 2: Apply the realm-android plugin to the top of the application level build.gradle file.
apply plugin: 'realm-android'
Step 3: Gradle sync
For the official complete installation guide. Please see the following link.
https://realm.io/docs/java/latest/#installation
The method I used is
` dependencies
{
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "io.realm:realm-gradle-plugin:3.1.4"
}`
in your main build gradle file
then add
apply plugin: 'realm-android'
and
compile 'io.realm:android-adapters:2.0.0'
in your app's build gradle
this link to bintray will give you the latest build
https://bintray.com/realm/maven/realm-android-library/3.4.0#files/io%2Frealm%2Frealm-android-library%2F3.4.0
I am trying to add ActionBarSherlock to my existing app. This is not as easy as I thought. I have been doing this for two days now. I have tried every tutorial for 2 pages of Google results. Here is what I have after following this tutorial.
My project Structure
ActionBarSherlock/actionbarsherlock/ build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/Parse-1.3.1.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
ClashMMAProject/ClashMMA/ build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/Parse-1.3.1.jar')
compile project(':libraries:ActionBarSherlock:actionbarsherlock')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
setting.gradle
include ':ClashMMA', ':libraries:ActionBarSherlock:actionbarsherlock'
Dependancies
My Error
I have done a lot of research and I can't get anything to work. I get an error every time, so there is something I don't understand correctly. Please help. Thanks for your time.
Update
Ok after the suggestions, this is what I have in ClashMMAProject/ClashMMA/ build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
compile files('libs/Parse-1.3.1.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
This is producing an error:
Gradle: Execution failed for task ':ClashMMA:processDebugManifest'.
> Manifest merging failed. See console for more info.
I also struggled with this, as it seemed every tutorial or answer I followed left some small detail out that a beginner doesn't know as something to automatically do. Here is how I eventually got ABS added to my project:
1.Don't download ABS at all. You can completely add it by modifying your existing build.gradle file. Not your project's build.gradle, but your inner folder that is the parent folder of your src directory.
2.Open SDK Manager and make sure you have Android SDK Build-tools 18.0.1 (later versions might also work).
3.Model your build.gradle file after mine. This is the exact build.gradle file I am using that works. Make sure your minSdk and targetSdk match what is in your manifest:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 18
}
}
4.Make sure you are using gradle 1.8 in gradle-wrapper.properties:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
5.Sync project with gradle files by pressing the button:
The ActionBarSherlock author has provided a .aar file, so you will no longer need to build the library that you have in your libraries folder. You can change your build.gradle to be something like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/Parse-1.3.1.jar')
}
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Note the actionbarsherlock aar file in dependencies, and the removal of the library dependency. (I also see that your gradle is at 0.5.+ and your buildToolsVersion is at "17.0.0", the most recent versions are 0.6.+ and "18.1.1", but you can work on those once ABS is working for you).
Now you can safely remove your libraries/ActionBarSherlock, which you will no longer need, and change your settings.gradle file to:
include ':ClashMMA'
Hope this helps.
I've referenced roboguice 2.0 in my new Android project build with Android Studio, here is my build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile files('/libs/android-support-v4.jar')
compile 'org.roboguice:roboguice:2.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
}
Both gradle clean and gradle build run successfully but the IDE is reporting the error Element resources must be declared in roboguice.xml
Am I missing something or is this a bug in the IDE?
Mystery solved,
I've accidentally copied roboguice.xml to res/menu instead of res/values