我已经负责修改了几年前由第三方公司创建的现有android应用。如您所料,我在编译和工作源代码方面遇到问题。最终目的是为其他地区制作该应用程序的新版本。
虽然我担任这项工作,但我的编码专业知识是Python Matlab等而不是Java的知识,而我正在努力解决其问题,这超出了我的专业知识(后端,数据处理等)。
我可以让该应用程序在模拟器上编译和运行,这里的先前文章非常有帮助,但是当我提出涉及C代码的请求时,该应用程序将崩溃。
该应用程序是潮汐应用程序,使用C代码计算潮汐高度和洋流。它使用NDK和JNI进行此操作,当前错误消息很长,因此我将尝试发布希望相关的内容。...
07-26 09:20:09.307 3730-3730/com.noc.anytide A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: expected a constructor but void com.noc.anytide.POLPredict$POLPredictResult.populateResult(double[], float, long, long): 0x86aac464
art/runtime/java_vm_ext.cc:470] in call to NewObjectV
art/runtime/java_vm_ext.cc:470] from com.noc.anytide.POLPredict$POLPredictResult com.noc.anytide.POLPredict.POLPredictShim(double, int, long[], long[], long[], double, int, int, int, float, long, int)
art/runtime/java_vm_ext.cc:470] "main" prio=5 tid=1 Runnable
art/runtime/java_vm_ext.cc:470] | group="main" sCount=0 dsCount=0 obj=0x7488b000 self=0xa990b400
art/runtime/java_vm_ext.cc:470] | sysTid=3730 nice=1 cgrp=default sched=0/0 handle=0xadc5d534
与此相关的Java文件如下:
package com.noc.anytide;
import android.annotation.SuppressLint;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
public class POLPredict {
public static double duration = (10f * 24f);
public static int nvals = 400;
public static long offset;
public static float maxY;
public static double currentHeight, prevHeight, nextHeight;
public static boolean rising;
public static boolean dataClippedLeft = false;
public static boolean dataClippedRight = false;
private native POLPredictResult POLPredictShim(double duration, int nvals, long Hi[], long Gi[], long Ki[], double ref_height, int Base_dd, int Base_mm, int Base_yy,
float startTime, long startDateTime, int constit_count);
static {
System.loadLibrary("POLPredict");
}
@SuppressLint("SimpleDateFormat")
public static String unixToString(long timestamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM HH:mm");
Date date = new Date(timestamp);
dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"));
return dateFormat.format(date);
}
public class POLPredictResult {
public List<Number> result;
public List<Number> dates;
public int numVals;
public void populateResult(double resultArray[], float maxRange, long startDateTime, long interval) {
result = new ArrayList<Number>();
dates = new ArrayList<Number>();
long currentTime = System.currentTimeMillis();
long prevTime = currentTime - 1800000;
long nextTime = currentTime + 1800000;
boolean containsCurrentTide = false;
maxY = 0.0f;
numVals = resultArray.length;
boolean valid = false;
boolean partiallyValid = false;
long pStart = 0;
long pEnd = 0;
long endDataTime = (startDateTime + (interval * numVals));
if(startDateTime <= currentTime && endDataTime >= currentTime) {
containsCurrentTide = true;
} else {
currentHeight = -1.0;
}
dataClippedLeft = false;
dataClippedRight = false;
if(BookMarksHandler.isNL) {
valid = true;
} else {
for(int i=0;i<InAppPurchasing.tidalPurchases.size();i++) {
long s = InAppPurchasing.tidalPurchases.get(i).start;
long e = InAppPurchasing.tidalPurchases.get(i).end;
if(InAppPurchasing.tidalPurchases.get(i).purchased ) {
if(startDateTime > s && endDataTime < e) {
valid = true;
break;
}
if((startDateTime > s && startDateTime < e) || (endDataTime > s && endDataTime < e)){
partiallyValid = true;
pStart = s;
pEnd = e;
break;
}
}
}
}
boolean wroteLevel = false;
for (int i = 0; i < numVals; i++) {
if(!valid && !partiallyValid && ((currentTime - (12*3600000) > startDateTime) || (currentTime + (12*3600000) < startDateTime))) {
if(wroteLevel) {
dataClippedRight = true;
} else {
dataClippedLeft = true;
}
this.result.add(-10.0);
} else if(partiallyValid) {
if(startDateTime > pStart && startDateTime < pEnd) {
this.result.add((Number) resultArray[i]);
wroteLevel = true;
} else {
if(wroteLevel) {
dataClippedRight = true;
} else {
dataClippedLeft = true;
}
this.result.add(-10.0);
}
} else {
this.result.add((Number) resultArray[i]);
wroteLevel = true;
}
if(containsCurrentTide && startDateTime < currentTime) {
currentHeight = (double) Math.round(resultArray[i] * 100) / 100;
}
if(containsCurrentTide && startDateTime < prevTime) {
prevHeight = (double) Math.round(resultArray[i] * 100) / 100;
}
if(containsCurrentTide && startDateTime < nextTime) {
nextHeight = (double) Math.round(resultArray[i] * 100) / 100;
}
this.dates.add(startDateTime);
startDateTime += interval;
}
maxY = maxRange;
if(nextHeight > prevHeight) rising=true;
else rising = false;
}
public void populateCurrentResult(double resultArray[], float maxRange, long startDateTime, long interval) {
result = new ArrayList<Number>();
dates = new ArrayList<Number>();
for (int i = 0; i < resultArray.length; i++) {
this.result.add((Number) resultArray[i]);
this.dates.add(startDateTime);
startDateTime += interval;
}
}
}
public POLPredictResult POLPredictGo(double duration, int nvals, long Hi[], long Gi[], long Ki[], double ref_height, int Base_dd, int Base_mm, int Base_yy, float startTime, long unixStartTime, int constit_count) {
return POLPredictShim(duration, nvals, Hi, Gi, Ki, ref_height, Base_dd, Base_mm, Base_yy, startTime, unixStartTime, constit_count);
}
}
是否有明显的迹象表明可能是问题或错误消息的原因? JNI和NDK库从2015年开始使用到今天,是否会引起人们的注意?
我很高兴提出这个问题,但是对于此问题/错误,一些指示和典型原因将非常有帮助。