简体   繁体   中英

Using Maven Inside of Android Studios

I have been doing heavy searching on this for a few days now. I find results but it ether applies to an older version or doesn't apply to my situation.

I have a Maven Project That I built inside Eclipse. I've done a Maven install and Maven build via Eclipse. I use the Maven project with another Java Application and it works fine once I run the install.

I want to use the same maven project inside of Android Studio. I pretty sure I need to do something within build.gradle but there are 2 different ones and I'm not sure which one the dependencies need to be placed in or what needs to go where.

I get no errors when I'm writing the code and the problem happens during run-time with missing class definitions

I'm not sure how to tell the gradle to download the required dependencies

app (build.gradle):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.soleo.api.sdk_demo"
        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.1.1'
    compile 'SoleoLocalSearchAPI:SoleoLocalSearchAPI:0.0.1-SNAPSHOT'
}

SDK_Demo (build.gradle)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

MainActivity.java:

package com.soleo.api.sdk_demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.soleo.LocalSearch;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String api = "XXXXXXXXXXXX";
        String ani = "##########";

        LocalSearch localSearch = new LocalSearch(api, ani);


    }
}

I think the problem is related to your dependency SoleoLocalSearchAPI. Please ensure that this dependency has been installed to your local maven repository. If you want to download this dependency from another remote repository, you have to define it as follows :

buildscript {
    repositories {
        jcenter()
        maven { url 'http://blablabla.com' }
    }
.......
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM