我创建了一个具有C ++支持的新Android Studio项目,但没有添加任何内容。该项目使用CMake进行构建,编译和运行。然后,我将以下两行代码添加到文件底部的import requests
from bs4 import BeautifulSoup
url = 'https://epaper.thehindu.com/'
req_url = 'https://epaper.thehindu.com/Login/ValidateLogin'
with requests.Session() as session:
res = session.get(url)
soup = BeautifulSoup(res.text,"lxml")
payload={
'__RequestVerificationToken':soup.select_one("[name='__RequestVerificationToken']")['value'],
'Email':'', #your email
'Password':'', #your password
'hiddenTab':''
}
r = session.post(req_url,data=payload)
soup = BeautifulSoup(r.text,"lxml")
print(soup.title)
中,并收到CMake构建错误。
CMakeLists.txt
这是我在构建项目时遇到的错误
find_package(Java COMPONENTS Development) # Line 47
find_package(JNI REQUIRED) # Line 48
CMake在从命令行调用时运行,但是由于某些原因在Android Studio中失败,我不确定为什么。
编辑1
这是CMakeOutput.log文件
编辑2
这就是-- Found Java: /usr/lib/jvm/java-10-oracle/bin/java (found version "10.0.1") found components: Development
-- Configuring incomplete, errors occurred!
CMake Error at /home/xxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
See also "/home/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/release/x86_64/CMakeFiles/CMakeOutput.log".
JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
Call Stack (most recent call first):
/home/xxxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
/home/xxxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindJNI.cmake:314 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:48 (find_package)
External native generate JSON release: JSON generation completed with problems
文件中的所有内容。它使用cmake命令在cmd中编译。
CMakeLists.txt
这是cmd输出
cmake_minimum_required(VERSION 3.4.1)
find_package(Java COMPONENTS Development)
find_package(JNI REQUIRED)
当我尝试使用gradle在Android Studio中对其进行编译时,在Windows 10专业版64位操作系统上出现以下错误
E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\build>cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/build
答案 0 :(得分:2)
与Android捆绑在一起的CMake版本试图告诉您,由于缺少某些部分,它找不到JNI软件包:
missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH
在文档中查找FindJNI(https://cmake.org/cmake/help/latest/module/FindJNI.html),将这些变量设置为Android版本的JNI未附带的库和标头的位置(不足为奇,例如,Android不包含AWT库)。
运行find_package(JNI REQUIRED)
时,FindJNI代码检查是否设置了这些变量,如果没有设置,则发出错误。
一种解决方法是在调用find_package
之前自行设置这些变量:
# We are only interested in finding jni.h: we do not care about extended JVM
# functionality or the AWT library.
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_INCLUDE_PATH2 NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
find_package(JNI REQUIRED)
但是请注意,您的代码将只能使用 jni.h 及其功能:如果尝试访问JNI包的任何其他部分,它将失败(可能在编译时) ),因为实际上,您欺骗CMake认为找到了整个软件包,而实际上其中只有一部分存在于Android设置中。
答案 1 :(得分:0)
class Widget:
pass
class Dialog:
def __getattr__(name) -> Widget:
pass
已解决
Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
答案 2 :(得分:0)
与alpine:edge码头工人映像相同,已使用:
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
RUN apk add --no-cache openjdk8
ref:https://pkgs.alpinelinux.org/contents?branch=edge&name=openjdk8&arch=x86_64&repo=community