使用maven构建android项目

Android整合Maven笔记(一)——在Android项目上启用maven 眼下Android的开发正如火如荼,开发方式大多数是Android SDK+Eclipse+ADT,大部分的操作都要依赖Eclipse(当然有高手直接敲命令的)。如果项目依赖其它库资源在不同的机器上难免又要设置一番,而且库资源及其依赖管理是相当混乱,针对这种情况,Maven是一个很好的解决方案,下面讲叙述如何将Android的工程与Maven整合。 首先介绍一下需要用到的工具: Android 阅读详情

为什么引入maven构建方式

做过java后台开发的人员应该都知道,maven使用解决依赖包管理问题的,同时优化测试,打包,部署等流程的.

在android里,

  • maven可以管理你的依赖包
  • 打包成apklib,管理自己的组件库
  • 动态配置你的发布渠道(此点非常方便)
  • 签名,打包,混淆一条龙服务.

开始使用maven

引入pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>apkDeplorer</artifactId>
    <version>1.0.0</version>
    <packaging>apk</packaging>
    <name>apkDeplorer</name>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>4.1.1.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v4</artifactId>
            <version>r7</version>
        </dependency>
    </dependencies>

    <properties>
        <keystore.filename>apkDeplorer.keystore</keystore.filename>
        <keystore.storepass>kison.chen@zaozao</keystore.storepass>
        <keystore.keypass>kison.chen@zaozao</keystore.keypass>
        <keystore.alias>kison-android-app</keystore.alias>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <finalName>${project.artifactId}-${project.version}-${manifest.metadata.id}</finalName>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>.</directory>
                <filtering>true</filtering>
                <targetPath>../filtered-resources</targetPath>
                <includes>
                    <include>AndroidManifest.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>**/env-*.properties</exclude>
                </excludes>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>3.6.0</version>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>run</id>
                            <goals>
                                <goal>deploy</goal>
                                <goal>run</goal>
                            </goals>
                            <phase>install</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <proguardConfig>proguard-project.txt</proguardConfig>
                        <proguardSkip>${project.build.proguardSkip}</proguardSkip>
                        <manifestDebuggable>${manifest.debuggable}</manifestDebuggable>
                        <androidManifestFile>target/filtered-resources/AndroidManifest.xml
                        </androidManifestFile>
                        <release>${project.build.release}</release>
                        <run>
                            <debug>${project.build.debug}</debug>
                        </run>
                        <runDebug>${project.build.runDebug}</runDebug>
                        <sign>
                            <debug>${project.build.sign.debug}</debug>
                        </sign>
                        <undeployBeforeDeploy>true</undeployBeforeDeploy>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <sdk>
                        <platform>15</platform>
                    </sdk>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>keytool-maven-plugin</artifactId>
                <version>1.2</version>
                <configuration>
                    <keystore>${keystore.filename}</keystore>
                    <storepass>${keystore.storepass}</storepass>
                    <keypass>${keystore.keypass}</keypass>
                    <alias>${keystore.alias}</alias>
                    <dname>CN=iKoding, OU=iKoding, O=iKoding, C=CN</dname>
                    <sigalg>SHA1withDSA</sigalg>
                    <validity>10000</validity>
                    <keyalg>DSA</keyalg>
                    <keysize>1024</keysize>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>debug</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>src/main/resources/env-debug.properties</filter>
                </filters>
            </build>
            <properties>
                <project.build.debug>true</project.build.debug>
                <project.build.runDebug>false</project.build.runDebug>
                <project.build.proguardSkip>true</project.build.proguardSkip>
                <project.build.release>false</project.build.release>
                <project.build.sign.debug>true</project.build.sign.debug>
                <manifest.debuggable>true</manifest.debuggable>
            </properties>
        </profile>
        <profile>
            <id>release</id>
            <properties>
                <project.build.debug>false</project.build.debug>
                <project.build.runDebug>false</project.build.runDebug>
                <project.build.proguardSkip>false</project.build.proguardSkip>
                <project.build.release>true</project.build.release>
                <project.build.sign.debug>false</project.build.sign.debug>
                <manifest.debuggable>false</manifest.debuggable>
            </properties>
            <build>
                <filters>
                    <filter>src/main/resources/env-release.properties</filter>
                </filters>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <version>1.2</version>
                        <executions>
                            <execution>
                                <id>sign</id>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <phase>package</phase>
                                <inherited>true</inherited>
                                <configuration>
                                    <includes>
                                        <include>${project.build.outputDirectory}/*.apk</include>
                                    </includes>
                                    <keystore>${keystore.filename}</keystore>
                                    <storepass>${keystore.storepass}</storepass>
                                    <keypass>${keystore.keypass}</keypass>
                                    <alias>${keystore.alias}</alias>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- 渠道profiles -->
        <profile>
            <id>channel-test</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <manifest.metadata.id>test</manifest.metadata.id>
                <manifest.metadata.channel>test</manifest.metadata.channel>
            </properties>
        </profile>
        <profile>
            <id>channel-91</id>
            <properties>
                <manifest.metadata.id>91-market</manifest.metadata.id>
                <manifest.metadata.channel>91 market</manifest.metadata.channel>
            </properties>
        </profile>
        <profile>
            <id>channel-yingyonghui</id>
            <properties>
                <manifest.metadata.id>yingyonghui-market</manifest.metadata.id>
                <manifest.metadata.channel>yingyonghui market</manifest.metadata.channel>
            </properties>
        </profile>
        <profile>
            <id>channel-tongbutui</id>
            <properties>
                <manifest.metadata.id>tongbutui-market</manifest.metadata.id>
                <manifest.metadata.channel>tongbutui market</manifest.metadata.channel>
            </properties>
        </profile>
        <profile>
            <id>channel-tengxun</id>
            <properties>
                <manifest.metadata.id>tengxun-market</manifest.metadata.id>
                <manifest.metadata.channel>tengxun market</manifest.metadata.channel>
            </properties>
        </profile>
        <profile>
            <id>channel-anzhi</id>
            <properties>
                <manifest.metadata.id>anzhi-market</manifest.metadata.id>
                <manifest.metadata.channel>anzhi market</manifest.metadata.channel>
            </properties>
        </profile>
        <profile>
            <id>channel-gfan</id>
            <properties>
                <manifest.metadata.id>gfan</manifest.metadata.id>
                <manifest.metadata.channel>gfan</manifest.metadata.channel>
            </properties>
        </profile>
    </profiles>
</project>

安装本地依赖包

由于国内的第三方库多未以maven形式打包,故我们要手动将jar包安装到本地maven库.(高德地图为例)

mvn install:install-file -DgroupId=com.autonavi -DartifactId=libamapv3 -Dversion=v3 -Dfile=/Users/keepcleargas/Downloads/AMapSDKV2Demo/libs/armeabi/libamapv3.so -Dpackaging=so -DgeneratePom=true -Dclassifier=armeabi  

mvn install:install-file -DgroupId=com.autonavi -DartifactId=location -Dversion=2.0.0 -Dfile=/Users/keepcleargas/Downloads/AMapSDKV2Demo/libs/MapApiLocation.jar -Dpackaging=jar -DgeneratePom=true

添加依赖包到pom.xml

<dependency>
          <groupId>com.autonavi</groupId>
           <artifactId>libamapv3</artifactId>
           <version>v3</version>
           <classifier>armeabi</classifier>
            <scope>runtime</scope>
            <type>so</type>
  </dependency>
  <dependency>
              <groupId>com.autonavi</groupId>
              <artifactId>map</artifactId>
              <version>2.0.0</version>
  </dependency>
  <dependency>
               <groupId>com.autonavi</groupId>
               <artifactId>ApiLocation</artifactId>
               <version>2.0.0</version>
  </dependency>
   <dependency>
               <groupId>com.autonavi</groupId>
               <artifactId>ApiSearch</artifactId>
                <version>2.0.0</version>
   </dependency>

android的maven版本构建

由于在maven central中 android版本只有4.1.1.4

我们需要一个工具来安装新版的android sdk. Maven Android SDK Deployer.

根据Maven Android SDK Deployer的wiki 文案,mvn install -P 4.4 在pom.xml导入 4.4.2的安卓包.

<dependency>
            <groupId>android</groupId>
            <artifactId>android</artifactId>
            <version>4.4.2_r3</version>
            <scope>provided</scope>
        </dependency>

构建中可能出现的问题

  • maven版本问题 使用过程中可能会出现版本问题,笔者这里用的是maven 3.1.1,com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2
  • .9图片问题
ERROR: 9-patch image Project/res/drawable-  hdpi/input_03_mid.9.png malformed.
 [INFO]        Must have one-pixel frame that is either transparent or white.
  [INFO] ERROR: Failure processing PNG image Project/res/drawable-hdpi/input_03_mid.9.png

将.9图片标准化 即可

命令执行

mvn clean package

打包,但不部署。
mvn clean install

打包,部署并运行。
mvn clean package android:redeploy android:run

这个命令通常用于手机上已经安装了要部署的应用,但签名不同,所以我们打包的同时使用redeploy命令将现有应用删除并重新部署,最后使用run命令运行应用。
mvn android:redeploy android:run

不打包,将已生成的包重新部署并运行。
mvn android:deploy android:run

部署并运行已生成的包,与redeploy不同的是,deploy不会删除已有部署和应用数据。 

mvn clean install -Prelease,channel-91

打包签名,的渠道为channel-91的apk

参考文献

Maven本地仓库中安装android和uiautomator 安卓自动化测试、maven本地仓库安装uiautomator和android、maven引用本地jar包 阅读详情

相关推荐

嵌入式学习笔记- 关于电容的纹波电流

纹波电流是导致电解电容发热、影响其寿命的关键交流电流成分。它不是一种特殊的电流,而是电路中必然存在的现象。要重视,不能忽视。必须保证电路中的纹波电流 < 电容的额定纹波电流。电容鼓包爆浆,要怀疑是否是纹波电流过大或电容ESR变大所致。希望这个解释能帮助您彻底理解这个概念!二 电容纹波电流与频率的关系在大多数情况下,频率越高,电容所能承受的额定纹波电流值越大。【个人理解:因为频率越低ESR越大,具体见第三节ESR与频率的关系】下面我为您详细解释为什么会这样,以及在实际应用中如何考虑。

qq_35771411的博客 2187

Android中maven的理解和使用

解释

“点点”专栏 2800

从选型到调试:MCU外部晶振电路设计的实战避坑指南

本文详细解析了MCU外部晶振电路设计的关键要点,从选型到调试提供全面指南。重点探讨了晶振频率选择、负载电容计算、PCB布局优化等核心问题,并分享常见故障排查技巧与EMC设计经验,帮助工程师规避设计陷阱,提升嵌入式系统时钟稳定性。

weixin_30872577的博客 276

Android本地Maven库创建及使用

在某些情况下,公司的多个项目都会有一些共通的核心库。一旦修改起来,多个项目来回修改很麻烦,也很容易乱。所以可以将相关的核心库提取出来做成一个library,创建一个本地maven库。多个项目引用起来就方便多了。维护起来也简单。 创建一个核心库的工程 创建一个新的Android工程,直接选择任意模板,或者Empty都可以 点击File -> New -> Moudule ->Android Library, 点击Next,然后需要配置包名等信息,点击Finish完成即可 然后就

自由空间 3761

基于传输门与传输管逻辑的全加器设计

全加器是指对输入的两个二进制数相加(A与B)同时会输入一个低位传来的进位(Ci-1),得到和数(SUM)和进位(Ci)。一位全加器可以处理低位进位,并输出本位加法进位。由于这种晶体管的漏极和源极完全可以互换使用,因此这种电路的输入端与输出端也可以互换,这就是具有信号传输双向特性的传输管。传输管的输入信号可以传输到输出端,同时输出端的信号也可以传输到输入端。半加器是指对输入的两个一位二进制数相加(A与B),输出一个结果位(SUM)和进位(C),没有进位的输入加法器电路,是一个实现一位二进制数的加法电路。

qq_40353731的博客 4381

达梦数据库与sharding-jdbc的深度适配实践

本文详细介绍了达梦数据库与sharding-jdbc的深度适配实践,包括驱动与依赖管理、核心适配实现、注册与配置等关键步骤。通过扩展shardingSphere的方式,成功实现了达梦数据库的分库分表功能,并提供了常见问题解决方案和性能优化建议,助力企业级应用高效处理海量数据。

weixin_30300225的博客 623

将一个Android项目修改为能够使用Maven进行构建

将一个Android项目修改为能够使用Maven进行构建          初学maven,本文展示将一个已有的项目经过修改后直接用Maven进行编译、生成apk文件并安装到手机运行的过程。不涉及Eclipse及其maven插件。        将要修改的Demo的基本功能参见:http://blog.youkuaiyun.com/winstonwolfe/article/details/2842597

WinstonWolfe的专栏 1873

计算机视觉:相机模型与参数标定

一、相机投影模型 1、小孔成像 2、相机模型中的四个平面坐标系 3、像主点偏移 4、畸变现象与内参矩阵 5、外参矩阵 二、相机标定:张正友棋盘格标定法 1、张正友棋盘格标定法描述 2、计算外参和内参 2.1 计算单应性矩阵H 2.2 计算内参数矩阵 2.3 计算外参数矩阵 3、实验:MATLAB实现 3.1 实验数据 3.2实验过程 3.3 实验结果 4、实验:OpenCV实现 4.1 实现代码 4.2 实验结果 5、实验分析与总结

DreamWendy的博客 2514

使用maven对android项目进行构建

软件需求: 1.JDK 1.6+ Android SDk(r21.1 或者最新,版本越新支持越高) Maven 3.1.1+ 添加环境到path,新建变量ANDROID_HOME,写上你的sdk的安装路径,例如 ANDROID_HOME:E:\installspace\Android\android-sdk;path变量中添加%ANDROID_HOME%\tools and %AN...

tonysh_zds的博客 745

使用 Python 构建 Reddit 热帖爬虫:抓取热门讨论帖和评论

在现代互联网中,Reddit 被誉为全球最大、最活跃的讨论平台之一,汇聚了各种主题的帖子、评论和社交互动。因此,抓取 Reddit 上的热门帖子和评论可以为我们提供一个丰富的文本数据源,可以用于情感分析、话题建模、趋势分析等应用。Reddit 提供了官方的 API,可以让开发者获取包括帖子、评论、用户信息等在内的各种数据。我们可以结合上述方法,抓取多个热门帖子,并将每个帖子的标题、作者、发布时间和评论内容保存到一个数据结构中。每个帖子的对象包含了丰富的信息,如标题、内容、发布时间、作者等。

2201_76125261的博客 381

【用unity实现100个游戏之7】实现一个类《杀戮尖塔》的卡牌回合制游戏(附项目源码)

【用unity实现100个游戏之7】实现一个类《杀戮尖塔》的卡牌回合制游戏(附项目源码)

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1万+

使用Maven构建Android项目

文章地址:使用Maven构建Android项目 ← iKoding的博客  

iKoding的博客 206

SAP在sap我定义了三个帐套 T9 SGD,I9 CNY, C9 CMY 想使用三个不同的币种,那么 我在定义和激活非主分类账时 如何定义各自的币种 ?

摘要:在SAP中为非主分类账(T9、I9、C9)配置不同币种(SGD、CNY、MYR),需通过三个步骤实现:1)在FINSC_LEDGER中定义分类账货币类型;2)在OB22中为公司代码0919配置平行货币;3)在"定义和激活非主分类账"中关联币种。关键注意事项包括维护自定义货币类型(以Y/Z开头)、设置OB08汇率以及独立汇率评估。完成后可通过FB50测试凭证和FAGLL03验证各账套的币种金额显示。

金牌架构师 1011

使用Maven构建Android白盒自动化测试项目

使用Maven构建Android白盒自动化测试项目   本文展示应用maven来构建一个简单的Android白盒测试的项目的过程。基本过程如下:   1.新建一个名为Demo的Android应用,需要注意的是代码文件位于Demo\src\main\java路径下。 2.针对Demo应用,新建一个Android测试项目DemoTest,测试项目的代码文件位于DemoTest\src\mai

WinstonWolfe的专栏 1439

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

IntelliJ 使用Maven构建Android项目过程

这是我的第一篇博客!对我的意义十分重大!在这篇博客的编写过程就是我在使用Maven构建Android项目中踩过的坑的记录。在此由于本人的水平有限,这篇文章也只能当作经验借鉴而已,希望后来者能够避开这些我曾经犯过的坑。 以下记录一下这个过程: 1.下载IntelliJ,Maven这里就不赘述了,提供IntelliJ的下载链接[官方下载](https://www.jetbrains.com/idea/)

xv545262342的博客 2204

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

安卓项目构建:Maven 安装配置与 Gradle 的配合使用

Maven 是一个强大的依赖管理和构建工具,而 Gradle 是安卓官方推荐的默认构建系统。两者可以配合使用,例如通过 Maven 仓库来管理依赖,Gradle 则负责构建任务。通过以上步骤,您可以轻松在安卓项目中实现 Maven 与 Gradle 的配合。Maven 负责依赖存储,Gradle 负责构建执行,两者结合能显著提升开发效率。Gradle 是安卓项目的默认构建工具,负责编译代码、打包 APK 和管理依赖。在安卓项目中,让 Gradle 使用 Maven 仓库非常简单。

2501_94071933的博客 1533

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

android simple-xml,使用Maven构建Android项目-dexer在simple-xml依赖项上失败

我有绝对空的Android项目生成mvn archetype:generate -DarchetypeArtifactId=android-quickstart .......它构建良好,部署合理,运行良好.问题是,当我添加org.simpleframeworksimple-xml2.6.2依赖,构建失败,[INFO] --- android-maven-plugin:3.0.0:dex (def...

weixin_33421437的博客 303

搭建android开发环境 android studio

搭建android开发环境 android studio

susu1083018911的博客 6306
上一篇: 深入理解RunLoop
下一篇: Eclipse支持Tomcat8 添加WTP包插件到Eclipse Kepler中
focusjava
博客等级 码龄14年 127粉丝 528原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值