无法构建本机android jar文件

时间:2017-11-08 04:44:03

标签: android nativescript

build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 25

    }
    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.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    testCompile 'junit:junit:4.12'
}



// task to delete the old jar
task deleteOldJar(type: Delete) {
    delete 'release/ToastPlugin.jar'
}

// task to export contents as jar
task exportJar(type: Copy) {
    from('build/intermediates/bundles/release/')
    into('release/')
    include('classes.jar')
    // name the plugin
    rename('classes.jar','ToastPlugin.jar')
}

exportJar.dependsOn(deleteOldJar, build)

Toaster.java:

import android.content.Context;
import android.widget.Toast;

public class Toaster {
    public void show(Context context) {
        CharSequence text = "Hello NativeScript!";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();
    }
}

manifest.java:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.buildpack">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

    </application>

</manifest>

下面我发布了当我在gradle中点击导出jar时生成的最后一行截图。到目前为止,我还没有看到构建jar成功的消息。

enter image description here

1 个答案:

答案 0 :(得分:0)

在其gradle脚本中使用apply plugin: 'com.android.library'插件的Android库将输出.aars

有关构建aar的完整说明,请参阅https://developer.android.com/studio/projects/android-library.html。您想调用assembleassembleRelease任务来获取插件输出中的aar库。