前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」

Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」

作者头像
全栈程序员站长
发布2022-09-14 10:48:07
9150
发布2022-09-14 10:48:07
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

代码语言:javascript
复制
static {
		System.loadLibrary("serial_port");
	}

今天想连接串口做一个新功能 但是连接串口加载库的时候总是找不到serial_port库

1:

Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」
Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」

项目结构是这样的

Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」
Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」

库文件不多说 github很多

Android.mk

代码语言:javascript
复制
#
# Copyright 2009 Cedric Priscal
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 
#

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

TARGET_PLATFORM := android-3

LOCAL_MODULE    := serial_port
LOCAL_SRC_FILES := SerialPort.c


#LOCAL_MODULE    := serial_port
#LOCAL_SRC_FILES := SerialPort.c
LOCAL_LDLIBS    := -llog

include $(BUILD_SHARED_LIBRARY)

但是写完Android.mk为什么还是不识别呢?

这是什么原因造成的呢?

Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」
Android 加载串口通信读取信息时 AndroidStudio loadLibrary失败「建议收藏」

要加上这句话

我项目中的库文件是build.gradle

代码语言:javascript
复制
apply plugin: 'com.android.library'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }


        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    

    }

    dependencies {
        api fileTree(dir: 'libs', include: ['*.jar'])
        api fileTree(include: '*.jar', dir: 'libs')
        implementation 'androidx.appcompat:appcompat:1.1.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test.ext:junit:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }

    repositories {
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/159830.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档