In a bid to expand into the increasingly lucrative weapons market here, Nissan Motor Co. announced today an agreement with Martin Marietta Corp. of the United States to swap its industrial robot technology for aerospace and defense know-how.

The move by Nissan, Japan's second-ranking automaker, is important because it reflects mounting efforts by Japan's industrial giants to use their sophisticated commercial technology to embark aggressively on the production of arms and defense-related equipment, one of the most significant remaining areas of U.S. technical superiority.

Nissan officials said that under the terms of the broadly based, long-term agreement they would obtain basic technology from the large U.S. defense contractor to aid the company in its development of rocket engines, launching mechanisms and liquid propellants for use in missile production.

They refused to disclose any financial details of the agreement.

Citing the increasingly bleak outlook for worldwide car sales, Nissan officials said the company wants eventually to diversify into areas in which it can capitalize on technology so far developed for civilian purposes. They said that the high costs of independently designing and developing weapons and aerospace equipment had been a major obstacle.

"We chose Martin Marietta," a Nissan official said, "because American aerospace technology is so advanced and Japan still lags far behind. So we decided to get a bit of their know-how."

Japan's constitution forbids the export of military equipment, but Japanese corporations have, in recent years, boosted exports of their advanced technological products--computers, fiber optics, and telecommunications equipment, among others--which can be, and in some cases are, easily converted to military uses.

The Nissan announcement today also comes at a time when the United States is pressing Japan to ease its constraints on the export of those defense-related technological advances that the Japanese have achieved on their own. Under the 30-year-old mutual security ties between the two countries, the flow of military know-how so far has been overwhelmingly in Japan's favor, but Pentagon officials have asserted that it should be brought into better balance.

Nissan officials said that in return for Martin Marietta's know-how, Nissan, a world leader in the applications of robots for industrial use, will provide the U.S. company with expertise related to the production, uses and maintenance of robots. Officials declined to elaborate on the details of the agreement, but said it had been reached between senior representatives of the two companies in June.

Nissan officials, who did not want to be identified, said the agreement is central to the company's efforts to expand its business in the fields of aerospace and defense-related equipment.

The disclosure followed a report in the morning edition of Nihon Keizai Shimbun, a leading economic daily, which said that Nissan hopes to develop the initial agreement into an all-encompassing tie-up between the two companies. Company officials suggested that they had refrained from announcing the agreement earlier because they wanted to avoid potentially adverse publicity in Japan, where the issue of weapons development is particularly sensitive.

Nissan has been active in the production of launching systems and solid rocket fuels and is under contract with Japan's Defense Agency to supply parts for the production of Japan's current generation of short-range surface-to-air missiles and ASM1s (air-to-surface missiles) produced here under license from American manufacturers.

Company officials said that yearly sales of such items now amount to only $48 million out of Nissan's total sales of $13 billion, but indicated that the automaker plans to step up its defense-related production to win more orders under the country's expanding military budgets.

Under pressure from the United States to boost its military capabilities, Japan last month outlined a five-year defense program for the 1983-l987 period that included an $18 billion increase in spending on advanced weapons. Japan's budget for front-line military equipment for 1982 is $2.3 billion.

The direction toward more defense spending, and Tokyo's increasing emphasis on purchasing more equipment domestically produced in Japan has made the market an increasingly attractive one for Japanese manufacturers.

Industry analysts said today that, in tying up with Martin Marietta, Nissan has its eye on outpacing Mitsubishi, Japan's largest defense contractor, in competition for a production share in the country's next generation SAM-X (surface-to-air) missiles. Japanese defense officials, they said, are now torn between the Patriot system developed by Martin Marietta in cooperation with Raytheon and a prototype Phoenix system developed domestically by Mitsubishi. Tokyo is expected to make its final decision early next year.

Japan's weapons industry has been restricted by the country's longstanding policy banning the export of arms and defense-related technology and is minuscule by American standards. Japanese producers, all of whom rely on nondefense areas for the bulk of sales and profits, have been limited to selling weapons based solely on defense contracts awarded by the Defense Agency.

Nissan, company officials said today, has embarked on the program in cooperation with Hitachi Ltd. and Fuji Heavy Industries.

All three companies are members of the Fuyo Industrial Group, one of Japan's giant industrial conglomerates. Based on its experience in the development of sophisticated consumer electronics and computers, Hitachi is working on the development of missile control and guidance systems. Fuji, for its part, will concentrate on the production of rocket fuselages, Nissan officials said.

A Hitachi spokesman denied Japanese press reports that his company was involved in the tie-up with Martin Marietta. Fuji officials were unavailable for comment.