我已经提到了Creating native android packages and using them in nativesript。
我正在创建一个Android原生jar文件,我将在其中使用它 nativescript。
所以我按照那个教程。最后我无法构建一个jar文件。 我的本地项目文件夹中也没有创建发布文件夹。
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成功的消息。
答案 0 :(得分:0)
在其gradle脚本中使用apply plugin: 'com.android.library'
插件的Android库将输出.aars
有关构建aar
的完整说明,请参阅https://developer.android.com/studio/projects/android-library.html。您想调用assemble
或assembleRelease
任务来获取插件输出中的aar库。